Home How to pass parameters for method call in controller from gsp?
Reply: 2

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

Liam Paquette
1#
Liam Paquette Published in 2017-12-04 15:43:23Z

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?

Joch
2#
Joch Reply to 2017-12-05 13:07:29Z

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
elixir
3#
elixir Reply to 2017-12-07 16:08:17Z

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
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.301981 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO