It seems simple but is apparently very hard. Bind a (finite and known length) series of checkboxes to a list of booleans on a grails command object. It should of course be possible to "populate" the command object to restore the view, with the previous selected values.
E.g I have a grails webflow. It start out by binding 4 checkboxes to an entry in a boolean list. It switches to next state and prints the values - e.g. [true,true]. Navigate back, and all the checkboxes are empty (which makes perfectly sense - 4 checkboxes and only two values). So it should rather be e.g. [false, true, false, true].
No matter what I do, I cant seem to make this happen. In spring it would be easy, simply bind the checkbox to value[0]..[3]... Why is somehthing this simple so hard in Grails?!
Please help, it would really make my day!
Example Command Obj:
class TestCmdObj {
List<Boolean> boolListOne = []
}
Example binding method in controller (closure executed in flow action):
private def doBindAndValidateBoolList = {
bindData(flow.testCmdObj, params, [include:['boolListOne']])
}
So far so good. This actually works when displaying next page in flow, the testCmdObj.boolListOne displays true for the checkboxes checked..
The GSP code is simple, and uses:
<g:checkBox name="boolListOne"/>
<g:checkBox name="boolListOne"/>
<g:checkBox name="boolListOne"/>
<g:checkBox name="boolListOne"/>
In the next view, I can print out ${testCmdObj.boolListOne} and it prints out as many "true" values, as I checked of..(e.g. [true, true]) If I navigate back, the checkboxes are emtpy... Which, again, I can understand, since they all have the same name...