Search code examples
grailsgsp

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?


Solution

  • 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