Search code examples
grailsurl-mapping

Grails URLMappings uses the wrong URL


GSP CodeHow do I force Grails to use the correct URL in UrlMappings.groovy given identical paths, with one ending in $action and the other ending in $id? On triggering an action through the GSP file, my program goes into the id URL, causing an error.

Image shows the two URLs in question. I need to trigger the first URL, $action, on click of a button but instead the second URL is triggered


Solution

  • You are going to have a tough time here as the $id and $action are just variable names until they are assigned. They don't know that you are sending an id or an action, just that the url matches a pattern. You could do something like this though.

    "/workflow/**/$siteId/**/$iteration/**/$action?/$id?" (controller:"*****")
    

    You would have to always specify your action, ***/list/123 or ***/someAction would match, but not ***/123.

    You could also probably do some sort of constraint / logic in the mapping to sort things out, but that could get sort of messy.