Grails data binding and collection auto-grow limit
Among several great features of grails framework, data binding is one of them. In this we don’t have to create an instance of some class (domain or command object) and populate it to the request parameters after type casting. Grails did this for us.
Following is the way to bind request parameter “myDomains” to the command object property “myDomains”:
<g:each in="${myDomains}" var="myDomain" status="idx"> <tr> <td> <input type="checkbox" name="myDomains[${idx}].id" value="${myDomain.id}" checked> </td> </tr> </g:each>
- Command object
@Validateable class MyCO { List<MyDoamin> myDomains = ListUtils.lazyList([], FactoryUtils.instantiateFactory(MyDoamin)) static constraints = { myDomains nullable: false, validator: { val, obj -> if (val.size() < 1) { return "someError.code" } } } }
- Action
def myAction(MyCO myCO) { if (myCO.validate()) { ... } else { log.error "Some error message to the developer." ... } }
This code works great. Request parameter “myDomains” binds successfully with command object property.
BUT as soon as user select any checkbox whose idx (index) value is greater than 255 and then submit the form, nothing is binding in the myDomains property of MyCO class.
This is because collection auto-growth limit is 256 (Ref. DataBindingGrailsPlugin Line-65).
You can change this limit by setting grails.databinding.autoGrowCollectionLimit in Config.groovy file, eg.,
grails.databinding.autoGrowCollectionLimit=500
Hope this helps 🙂 .
Recent Comments