register
other register

Friday, March 20, 2009

Submit an array as a parameter

When you have an array of values to submit like the code below:

<g:each in="${people}" var="person">

<tr><td>
<input type="checkbox" name="emails[]" value="${person.email}" />
<td></tr>
</g:each>

When submiting this form, the emails[] will be submitted as an array/list object like [Ljava.lang.String;@151313a. To get the value out of the object, do:

params['emails[]'].toString()

That will get the value like: [joe@foo.com, blog@foo.com]