title: How to post a list to controller in Thymeleaf
body: <p>I am new to Thymeleaf,Maybe this is a simple question.Please help me.Thanks.</p>
  
  <p>Controller code:</p>
  
  <pre><code>@Controller
  public class TestController {
  
  @GetMapping(value = "/")
  public String testget(Map&lt;String, Object&gt; model) {
      TestBean bean = new TestBean();
      List&lt;Person&gt; list = new ArrayList&lt;&gt;();
      for (int index = 1; index &lt; 5; index++) {
          Person p = new Person();
          p.setId(index);
          p.setName("name" + index);
          list.add(p);
      }
      model.put("allList", "nothing");
      bean.setList(list);
      model.put("testbean", bean);
      return "NewFile";
  }
  
  @PostMapping(value = "/")
  public String testpost(Map&lt;String, Object&gt; model//
          , @ModelAttribute(name = "testbean") TestBean bean) {
      List&lt;Person&gt; list = bean.getList();
      model.put("bean", bean);
      model.put("allList", list.toString());
      return "NewFile";
  }}
  </code></pre>
  
  <p>simple mapper and a Person bean:</p>
  
  <pre><code>@Data
  public class TestBean {
  
     private List&lt;Person&gt; list;
  
  }
  
  @Data
  public class Person {
     private int id;
     private String name;
  }
  </code></pre>
  
  <p>HTML code : </p>
  
  <pre><code>&lt;form action="#" th:action="@{/}" th:object="${testbean}" method="post"&gt;
      &lt;p th:text="'ALL : ' + ${allList}"&gt;&lt;/p&gt;
      &lt;table&gt;
          &lt;tr th:each="person : ${testbean.list}"&gt;
              &lt;td&gt;Id:&lt;input type="text" th:value="${person.id}" 
               /&gt;&lt;/td&gt;
              &lt;td&gt;name: &lt;input type="text" th:value="${person.name}" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
      &lt;input type="submit" value="submit" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I want put list to page and change properties to refresh.
  but i don't know how to add <strong>th:field</strong> tag, I try to add </p>
  
  <pre><code>**th:field="*{testbean.list[__${index}__].id}"** 
  </code></pre>
  
  <p>but it failed with :</p>
  
  <pre><code>Invalid property 'testbean' of bean class [com.TestBean]
  </code></pre>
  
  <blockquote>
    <p>UPDATE1</p>
  </blockquote>
  
  <p>And i tried </p>
  
  <pre><code>th:field="*{list[__${index}__].id}"
  </code></pre>
  
  <p>I got a error Where I added <strong>th:field</strong></p>
  
  <pre><code>Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateProcessingException: Error during execution of processor 'org.thymeleaf.spring4.processor.attr.SpringInputGeneralFieldAttrProcessor' (NewFile:14)] with root cause
  java.lang.NumberFormatException: For input string: "null"
  </code></pre>
  
  <p>My questions is what i can do something that i can get a <strong>List</strong> in controller.</p>