title: spring thymeleaf - delete object from html table and pass id to controller
body: <p>I pass a list with objects from my controller to my html and thymeleaf creates a  for every object in the list. </p>
  
  <p>I want to delete an entry via a button and pass the object id to my controller in order to delete it from the database.</p>
  
  <p>However when I handle the post request in my controller the id attribute is emtpy. </p>
  
  <p>HTML with Thymeleaf:</p>
  
  <pre><code>&lt;tbody&gt;
       &lt;tr th:each="user : ${users}"&gt;
         &lt;td th:text="${user.personId}"&gt;&lt;/td&gt;
         &lt;td th:text="${user.firstName}"&gt;&lt;/td&gt;
         &lt;td th:text="${user.lastName}"&gt;&lt;/td&gt;
         &lt;td&gt;
             &lt;form th:action="@{delete_user}" method="post" th:object="${user}"&gt;
                &lt;input type="hidden" th:field="${user.personId}"/&gt;
                &lt;button type="submit" value="Submit" class="btn btn-danger"&gt;Delete&lt;/button&gt;
             &lt;/form&gt;
         &lt;/td&gt;
       &lt;/tr&gt;
  &lt;/tbody&gt;
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>@RequestMapping(value = "/delete_user", method = RequestMethod.POST)
  public String handleDeleteUser(@ModelAttribute("user") User user) {
      System.out.println(user.getPersonId());
      System.out.println("test");
      return "redirect:/external";
  }
  </code></pre>
  
  <p>How can I make this work?
  Or is there another way?</p>
  
  <p>Thanks!</p>