Binding embedded List of objects on a Thymeleaf template for a POST request
<p>I am developing a grocery store list web application. One feature should be (un)checking found/bought items on the list. Displaying all the values works fine. But when I check some checkboxes on some bought items and try to POST it afterwards the incomming <code>@ModelAttribute</code> in the spring MVC controller is null (except the id).</p>

<p>I hope you can help me. </p>

<p>Here are my classes: </p>

<pre><code>public class PurchaseList {

private Long id;
private List&lt;PurchaseItem&gt; purchaseItemList;
private DateTime purchaseDate;
private boolean done;
}


public class PurchaseItem {

private Long id;
private String purchaseItemName;
private PurchaseCategory purchaseCategory;
private PurchaseList purchaseList;
private boolean found;
}
</code></pre>

<p>The Controller:</p>

<pre><code>@RequestMapping(value="/{id}", method=RequestMethod.POST)  
public String postPurchaseList(@PathVariable(value="id") Long id, @ModelAttribute("purchaseList") PurchaseList purchaseList, Model model) {
  List&lt;PurchaseList&gt; notDonePurchaseList = purchaseListService.getNotDonePurchaseList();
  model.addAttribute("notDonePurchases", notDonePurchaseList);
  purchaseListService.savePurchaseList(purchaseList);
  return "purchaseList";
}
</code></pre>

<p>The Thymeleaf template</p>

<pre><code>&lt;form action="#" th:action="@{/purchaseList/{purchaseListId}/(purchaseListId=${purchaseList.id})}" th:object="${purchaseList}" method="post"&gt;
      &lt;table class="table table-bordered table-hover"&gt;
        &lt;thead&gt;
          &lt;tr&gt;
            &lt;td&gt;Found&lt;/td&gt;
            &lt;td&gt;Item&lt;/td&gt;
            &lt;td&gt;Category&lt;/td&gt;
          &lt;/tr&gt;
        &lt;/thead&gt;
        &lt;tr th:each="item,status : ${purchaseList.purchaseItemList}"&gt;
          &lt;td&gt;&lt;input type="checkbox" th:checked="${item.found}" th:value="*{purchaseItemList[__${status.index}__].found}" /&gt;&lt;/td&gt;
          &lt;td th:text="${item.purchaseItemName}"&gt;&lt;/td&gt;
          &lt;td th:text="${item.purchaseCategory.categoryName}"&gt;&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/table&gt;
      &lt;input type="submit" value="Submit" id="submit" /&gt;
      &lt;/form&gt;
</code></pre>

<p>I know that I doesn't set the other values (only the <code>found</code> property). Or is this the problem?</p>

<p>Best regards</p>

<p><strong>Edit:</strong></p>

<ol>
<li>Initialized as suggested the <code>ArrayList</code> purchaseItemList. Now an empty <code>ArrayList</code> is returned to the controller. </li>
</ol>