Red Viper
Red Viper

Reputation: 507

How do I add parameter in g:actionSubmit in Grails

This is my view

<g:textArea name="review"/>
<g:actionSubmit action="addReview" params="${[gameId : "${game.id}", gameTitle : "${game.gameTitle}"] }" value="Add Review" class="ui blue labeled submit icon button">
    <i class="icon edit"></i> Add Review
</g:actionSubmit>

In my addReview action when I do log.println(review) It works but when I do log.println(gameTitle) and log.println(gameId), it is null. I'm pretty sure ${game.gameTitle} and ${game.gameTitle} isn't null because it prints something when I put it on GSP.

Upvotes: 1

Views: 708

Answers (2)

xpusostomos
xpusostomos

Reputation: 1647

The answer isn't obvious, but it can be done...

<input type="submit" value="Add Review" formaction="addReview?gameId=${game.id}" class="ui blue labeled submit icon button"/>

Upvotes: 0

huguohuan
huguohuan

Reputation: 24

https://grails.github.io/grails-doc/3.0.x/ref/Tags/actionSubmit.html

you can not add parameters in g:actionSubmit tag. try like this:

<g:textArea name="review"/>
<input name="gameId" value="${game.id}" type="hidden" />
<input name="gameTitle" value="${game.gameTitle}" type="hidden" />
<g:actionSubmit action="addReview" value="Add Review" class="ui blue labeled submit icon button">
          <i class="icon edit"></i> Add Review
 </g:actionSubmit>

Upvotes: 1

Related Questions