Grails Reverse Url Mapping: Is there a way to build links based on the currently matched route? -
i'm trying build dynamic url mappings based on domain classes of grails project. goal use single generic controller, url decides domain being used processing. problem now, don't desired urls when using <g:link />
tag.
i tried following variants create url mappings:
static mappings = { holders.grailsapplication.domainclasses.each { "/admin/${it.propertyname}/$action?/$id?"(controller: "admin") } } static mappings = { "/admin/$domainclass/$action?/$id?"(controller: "admin") }
both variants work actual url matching. don't behavior of reverse url mapping grails. in case of variant 1, reverse mapping resolves last added url mapping admincontroller. case 2 have problem have pass domainclass-parameter every link-creating call, though theoretically not necessary, since information present in current request.
i know there possibility of using named url mappings , using <g:link mapping="mapping_name" />
. problem using generic application-wide partial-views, try provide necessary information creating link, <g:link action="something" />
.
this leads 2 questions:
- is there possibility g:link build url based on matched mapping in current request?
- is there way reference mapping matched current request, can implement desired behavior myself?
you define named mappings like
holders.grailsapplication.domainclasses.each { dc -> name((dc.propertyname):"/admin/${dc.propertyname}/$action?/$id?" { controller = "admin" domainclass = dc.propertyname }) }
with mapping name saved in params can do
<g:link mapping="${params.domainclass}">link text</g:link>
Comments
Post a Comment