title: Thymeleaf with SpringBoot - how to loop model and delete?
body: <p>I am using SpringBoot with Thymeleaf to build a trivial example to help me learn the two technologies.  </p>
  
  <p>I am basing my example on <a href="https://spring.io/guides/gs/handling-form-submission/" rel="nofollow">THIS GUIDE</a></p>
  
  <p>The entity is a Greeting which has an Id and a Content.</p>
  
  <p>I create the Greeting just fine, and I can list all the Greetings I've created.</p>
  
  <p>I then wanted to add a delete option against each Greeting in the list page.  When clicking delete, I want the object to be deleted and the list page served up again.</p>
  
  <p>Alas, when I load the list page I get this error:</p>
  
  <blockquote>
    <p>java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'greeting' available as request attribute</p>
  </blockquote>
  
  <p><strong>Controller and respository objects</strong></p>
  
  <pre><code>    @Controller
  public class GreetingController {
  
      @Autowired
      GreetingRepo gr;
  
      @RequestMapping(value="/greeting/list", method=RequestMethod.GET)
      public String greetingsForm(Model model) {
          model.addAttribute("greetings", gr.findAll());
          return "greeting/list";
      }
  
      @RequestMapping(value="/greeting/delete", method=RequestMethod.POST)
      public String deleteGreeting(@ModelAttribute("greeting") Greeting greeting) {
          gr.delete(greeting);
          return "redirect:/greeting/list";
      }
  
  
  }
  
  @RepositoryRestResource
  interface GreetingRepo extends JpaRepository&lt;Greeting, Long&gt; {
  
  }
  </code></pre>
  
  <p><strong>List.html page:</strong></p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
  &lt;html xmlns:th="http://www.thymeleaf.org"&gt;
  &lt;head&gt;
      &lt;title&gt;Getting Started: Handling Form Submission&lt;/title&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;h1&gt;Result&lt;/h1&gt;
      &lt;div th:each="greeting : ${greetings}"&gt;
          &lt;p th:text="'id: ' + ${greeting.id}" /&gt;
          &lt;p th:text="'content: ' + ${greeting.content}" /&gt;
          &lt;form action="#" th:action="@{/greeting/delete}" th:object="${greeting}" method="post"&gt;
              &lt;input type="hidden" th:field="*{id}"/&gt;
              &lt;input type="hidden" th:field="*{content}"/&gt;
              &lt;input type="Submit" value="Delete"/&gt;
          &lt;/form&gt;
      &lt;/div&gt;
      &lt;a href="/greeting/add"&gt;Add another&lt;/a&gt;
      &lt;a href="/greeting/list"&gt;Show All&lt;/a&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Would appreciate a push in the right direction here :-)</p>