How can I dynamically build a list of mappings - instead of:
class UrlMappings {
static mappings = {
\"/helpdesk/user/$action?/$id?\" (controller=\"helpde
You can embed the $controller variable, see the documentation.
static mappings = {
"/helpdesk/$controller/$action?/$id?"()
}
BTW, the mappings to controllers and, optional, their views are enclosed by normal brackets (), not curly ones {}.
Such Groovy Scripts (as UrlMappings.groovy) are parsed by a ConfigSlurper instance, which finally converts them to a ConfigObject that implements Map. Admittedly, I'm either not sure how this parsing is accomplished in detail.
EDIT:
Here's an UrlMappings.groovy that comes somewhat near to what you want. (Search for "/$_ctrl/$_action/$id?".) The code, BTW, gets evaluated at runtime. Nevertheless, I haven't been able to put the grailsApplication to work.
Another idea was to add a javax.servlet.Filter to the web application, i.e., by subclassing Grails' UrlMappingsFilter.