gsp parameter passing from controller

SomeEUGuy picture SomeEUGuy · Jan 7, 2011 · Viewed 29.2k times · Source

how can i pass parameters to a groovy server page via a controller that are not an instance of a domain class ?

Answer

Maricel picture Maricel · Jan 9, 2011

You put your parameters into the model object map returned to your GSP, for example:

def index = { def hobbies = ["basketball", "photography"] 
render(view: "index", model: [name: "Maricel", hobbies: hobbies]) }

Then you get those values accessing them by the name you use in your model map, for example:

My name is ${name} and my hobbies are:
<ul>
<g:each in="${hobbies}" var="hobby">
<li>${hobby}</li>
</g:each>
</ul>

That should display the following:

My name is Maricel and my hobbies are:

 - basketball
 - photography