In my Grails app, I have a URL mapped directly to a view in UrlMappings.groovy
"/geolocation"(view: "/geolocation/index")
I'm trying to generate a link to this view that includes request parameters with:
<g:link elementId="btnSrcDest" uri="/geolocation" class="mapInfo"
params="[mapType: 'foo']">
Click me
</g:link>
But this generates the following HTML
<a class="mapInfo" id="btnSrcDest" href="/myApp/geolocation">
Click me
</a>
Whereas I was expecting this:
<a class="mapInfo" id="btnSrcDest" href="/myApp/geolocation?mapType=foo">
Click me
</a>
Why is the params
attribute of g:link
being ignored?
If you use a uri
attribute then that is assumed to be the complete (webapp-relative) link and no further processing will happen. You could try making it a named URL mapping instead
name geo:"/geolocation" {
view = "/geolocation/index"
}
and then use
<g:link elementId="btnSrcDest" mapping="geo" class="mapInfo"
params="[mapType: 'foo']">