Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails - Add a parameter to the params map

I would like to add a single parameter to my params map, and bind the rest in a link. At the moment, I only bind the params classically as follows:

<g:link class="email" controller="administrator" action="test" params="${params}">Link text</g:link>

How could I add a parameter to the params map ?

Thank you in advance for you help. Regards,

EDIT:

Ok, I have find a way to do it.

params="${params + ['forwardURI': request.forwardURI]}"

I do not know if there is any more Grails-like way to do it. If there is one, I would be obliged to learn it ;)

like image 895
Alexandre Bourlier Avatar asked Oct 17 '11 18:10

Alexandre Bourlier


1 Answers

If you have to do this repeatedly, you could use the answer you've posted in a g:link wrapper Tag Library, as Tag Libraries have access to params and request.

def forwardAwareLink = { attr, body ->
    attr.params = params + ['forwardURI': request.forwardURI]
    out << g.link(attr, body)
}

And in the gsp:

<g:forwardAwareLink class="email" controller="administrator" action="test">Link text</g:forwardAwareLink>

If you want to use the tag with your own custom parameter map from the gsp, you can also use the following in the Tag Library:

attr.params = attr.params + ['forwardURI': request.forwardURI]
like image 152
schmolly159 Avatar answered Oct 21 '22 07:10

schmolly159