title: How to post values from checkboxes generated from an ArrayList to another objects ArrayList with form in Thymeleaf and Spring?
body: <p>I have a form that takes several inputs from the user to create an object and one of these inputs are a set of checkboxes.</p>
  <p>The checkboxes are generated from a <code>Model</code> with an <code>ArrayList</code> with <code>Grape</code> objects called <strong>&quot;GrapeList&quot;</strong> but I can't manage to figure out how to add them to the object that is created when submitting the form.</p>
  <p>My form looks like this:</p>
  <pre><code>&lt;form class=&quot;col-12&quot; action=&quot;#&quot; th:action=&quot;@{/admin}&quot; th:object=&quot;${Wine}&quot; method=&quot;post&quot;&gt;
          &lt;div class=&quot;row&quot;&gt;
              &lt;div class=&quot;col-1&quot;&gt;
                  &lt;label for=&quot;nameInput&quot;&gt;Name: &lt;/label&gt;
              &lt;/div&gt;
              &lt;div class=&quot;col-11&quot;&gt;
                  &lt;input class=&quot;w-100&quot; id=&quot;nameInput&quot; type=&quot;text&quot; th:field=&quot;*{name}&quot;&gt;
              &lt;/div&gt;
          &lt;/div&gt;
              &lt;div class=&quot;col-1&quot;&gt;
                  &lt;label for=&quot;descriptionInput&quot;&gt;Description: &lt;/label&gt;
              &lt;/div&gt;
              &lt;div class=&quot;col-11&quot;&gt;
                  &lt;textarea class=&quot;w-100&quot; id=&quot;descriptionInput&quot; type=&quot;text&quot; th:field=&quot;*{description}&quot;&gt;&lt;/textarea&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  ====================PROBLEM=======================
          &lt;div class=&quot;row&quot; th:each=&quot;grape: ${GrapeList}&quot;&gt;
              &lt;div class=&quot;col&quot;&gt;
                  &lt;label th:for=&quot;'grape' + ${grape.name}&quot; th:text=&quot;${grape.name}&quot;&gt;&lt;/label&gt;
              &lt;/div&gt;
              &lt;div class=&quot;col&quot;&gt;
                  &lt;input type=&quot;checkbox&quot; th:id=&quot;'grape' + ${grape.name}&quot; th:value=&quot;${grape.id}&quot; th:field=&quot;*{grapes.add()}&quot;&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  ====================PROBLEM=======================
  
          &lt;button class=&quot;btn btn-outline-success&quot; type=&quot;submit&quot; value=&quot;Submit&quot;&gt;Save&lt;/button&gt;
      &lt;/form&gt;
  </code></pre>
  <p>The form is creating a <code>Wine</code> Object that has an <code>ArrayList</code> with <code>Grape</code> Objects called <strong>&quot;grapes&quot;</strong>. The other input fields works fine but I dont know how to bind the arraylist to add a grape object for every checked box..
  The <code>th:field=&quot;*{grapes.add()}&quot;</code> is just there to describe what I'm trying to do..</p>
  <p>Any help is appreciated!</p>