robert
robert

Reputation: 247

grails g:link pass params

I have something like this:

<g:each in="${temp}">

  <li>Date: ${it.dateParticipated}, <br>Role: ${it.role}, <br>Acceptence: ${it.accepted}, <br>
  <g:link controller="conference" action="participated" id="${it.conference.id}">
     Conference: </g:link>${it.conference},<br>
Role: ${it.role}, <br>Status: ${it.status}</li><br>

  <br>
</g:each>

What i want to do is, when i click on 'Conference', the controller 'conference' with the method 'participated' is loaded, and the params 'it.conference' is passed. How can i pass this params in the g:link tag ?

I need this because, when i click in the 'conference' word, other page is loaded with the conference details with the id passed.

Upvotes: 20

Views: 39482

Answers (3)

Arye Rosenstein
Arye Rosenstein

Reputation: 4246

You need to wrap your entire params with ${ }, instead of wrapping every variable that you want to pass separately.

<g:each in="${temp}">

  <li>Date: ${it.dateParticipated}, <br>Role: ${it.role}, <br>Acceptence: ${it.accepted}, <br>
  <g:link controller="conference" action="participated" params="${[id: it.conference.id, role: it.role, status: it.status]}">
     Conference: </g:link>

  <br>
</g:each>

Upvotes: 6

Aaditya Bhatta
Aaditya Bhatta

Reputation: 75

params="[customerId: customer.id]"

Upvotes: 3

Kaleb Brasee
Kaleb Brasee

Reputation: 51915

Use the params attribute to pass in a map of parameters:

<g:link action="/conference/participated" id="${it.conference.id}" params="[foo: 'bar', bar: 'foo']">My Link!</g:link>

See the documentation for more examples.

Upvotes: 33

Related Questions