title: Binding multiple checkboxes to list in Grails
body: <p>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.</p>
  
  <p>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].</p>
  
  <p>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?!</p>
  
  <p>Please help, it would really make my day!</p>
  
  <p>Example Command Obj:</p>
  
  <pre><code>class TestCmdObj {    
      List&lt;Boolean&gt; boolListOne = []
  }
  </code></pre>
  
  <p>Example binding method in controller (closure executed in flow action):</p>
  
  <pre><code>private def doBindAndValidateBoolList = {       
      bindData(flow.testCmdObj, params, [include:['boolListOne']])
  }
  </code></pre>
  
  <p>So far so good. This actually works when displaying next page in flow, the testCmdObj.boolListOne displays true for the checkboxes checked..</p>
  
  <p>The GSP code is simple, and uses:</p>
  
  <pre><code>&lt;g:checkBox name="boolListOne"/&gt;
  &lt;g:checkBox name="boolListOne"/&gt;
  &lt;g:checkBox name="boolListOne"/&gt;
  &lt;g:checkBox name="boolListOne"/&gt;
  </code></pre>
  
  <p>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... </p>