title: Thymeleaf form for each object in list results in "Neither BindingResult nor plain target object"
body: <p>I have multiple objects inside a list and wanted to create a form for every object in that List (the user can only submit one object at once). But as soon as I use th:field instead of name and value I get an exception. Maybe someone can help me. It only happens when using the th:each; if I pass in a single object to the form it works... I reduced the problem to the minimum so its more readable :)</p>
  
  <p>Exception:</p>
  
  <p>java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'o' available as request attribute</p>
  
  <p>Controller class:</p>
  
  <pre><code>@Controller
  public class TestController {
  
      @GetMapping("/objectlisttest")
      public ModelAndView getObjectListTest() {
          ModelAndView mv = new ModelAndView("objectlisttest");
          List&lt;DataObject&gt; objects = new ArrayList&lt;&gt;();
          for (int i = 0; i &lt; 5; i++) {
              DataObject o = new DataObject();
              o.setText("Dataobject");
              objects.add(o);
          }
          mv.addObject("objects", objects);
          return mv;
      }
  
      @PostMapping("/objectlisttest")
      public ModelAndView editObjectListTest(DataObject o, BindingResult br) {
          System.out.println(o);
          return getObjectListTest();
      }
  
      public static class DataObject {
          private String text;
  
          public String getText() {
              return text;
          }
  
          public void setText(String text) {
              this.text = text;
          }
      }
  
  }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>&lt;div th:each="o : ${objects}"&gt;
      &lt;form th:object="${o}" th:action="@{/objectlisttest}" method="POST"&gt;
          &lt;label&gt;Text&lt;input type="text" th:field="*{text}"&gt;&lt;/label&gt;
          &lt;input type="submit"&gt;
      &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Thanks in advance</p>
  
  <p>EDIT:
  Changing the View to</p>
  
  <pre><code>&lt;div th:each="o : ${objects}"&gt;
      &lt;form th:object="${o}" th:action="@{/objectlisttest}" method="POST"&gt;
          &lt;label&gt;Text&lt;input type="text" th:value="*{text}" th:name="text"&gt;&lt;/label&gt; 
          &lt;input type="submit"&gt;
      &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>works. But th:field would be much nicer...</p>