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:

  1. is there possibility g:link build url based on matched mapping in current request?
  2. 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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -