Liam Paquette
Liam Paquette

Reputation: 79

How to pass parameters for method call in controller from gsp?

I am calling a method located in the controller from my gsp file. The method in question has a parameter that need be filled.

The following is currently how I have it and does not work.

<g:each in="${msdsLinkList}" status="i" var="msdsLink">
  <div id="msdsBox${i}" class="msdsBox">
    <g:link class="word-button" action="exportAttachment(msdsLink${i})"></g:link>
  </div>
</g:each>

How can I pass msdsLink${i} in to the exportAttachment method?

Upvotes: 0

Views: 1048

Answers (2)

elixir
elixir

Reputation: 1442

Try

<g:each in="${msdsLinkList}" status="i" var="msdsLink">
  <div id="msdsBox${i}" class="msdsBox">
    <g:link class="word-button" action="exportAttachment" id="${msdsLink.id}"></g:link>
  </div>
</g:each>

In your controller, you can retrieve the passed in value as

params.id

Upvotes: 1

Joch
Joch

Reputation: 230

In addition to elixir's answer, you can use params in your g:link tag:

<g:each in="${msdsLinkList}" status="i" var="msdsLink">
  <div id="msdsBox${i}" class="msdsBox">
    <g:link class="word-button" action="exportAttachment" id="${msdsLink.id}"
            params="[foo: 'bar', bar: 'foo', value: msdsLink.value]"></g:link>
  </div>
</g:each>

In your controller's method, you can simply use the params map :

params.id
params.foo
params.bar
params.value

Upvotes: 1

Related Questions