Reputation: 175
I have been searching on how to return an integer value from controller to the gsp. I tried using this:
def test(){
def val = 1;
return val;
}
but it does not work. Please help.
Upvotes: 2
Views: 4014
Reputation: 8199
The return
statement is used to return values from services
to controllers
.
If you want to pass values from the controller
to gsp
, use:
[variableNameInGSP : valueToBeReturned]
Upvotes: 2
Reputation: 3934
Add this code to your controller:
def test(){
def v = 10
render view:'test.gsp', model:[v:v]
}
Then, access the value from your test.gsp by "${v}"
Note that the render view
is optional for test.gsp, i've written it only for demo purpose.. (i.e change the gsp filename).
Hope it helps.
Upvotes: 2