I have a form, where user can enter many records of the same domain class. Each of these records should be validated after the submission. In case of successful validation the collection of records should be passed to another view, otherwise validation errors should be displayed in the same view preserving previously entered values. Validation should be done using dedicated command object.
To make better picture, form roughly looks like this:
I came up with a solution to map each record to a form (items list is returned from the initial action rendering the view):
<g:each in="${items}" var="item">
<g:render template="orderItem" model="[item: item]"/>
</g:each>
And the template:
<form>
...
<g:textField value="${item.url}" name="url"></g:textField>
...
</form>
But I'm not sure about the correctness of this approach.
When implementing this scenario I faced few challenges:
- Is there a better way to map each record instance to the row of fields in the view so that a row of fields would represent one record?
- How to pass and validate the whole collection in one call to controller action?
Thanks in advance.