I have a structure with the following domain classes:
class Service{ static hasMany=[serviceRequirements:ServiceRequirement]}
And of course a bunch of member variables…
Problem occurs when I’m trying to set the properties in the controller like this:
service.properties = params
I get the following error:
Executing action [update] of controller [se.hb.eme.DeveloperController] caused exception: Invalid property 'serviceRequirements[0]' of bean class [se.hb.eme.Service]: Index of out of bounds in property path 'serviceRequirements[0]'; nested exception is java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
There’s pretty much no documentation on grails.org about this and I really can’t figure out the problem…
The .gsp is pretty simple. (I removed some fields…)
<g:form action="create">
<g:textField name="header" />
<g:textField name="serviceRequirements[0].header" />
<g:submitButton value="Create" />
If I understand it correctly that’s because the code is trying to set element 0 of a list, which has no elements in it, thus throwing an index out of bounds exception.
Try this in your domain class: