title: Spring and Thymeleaf: Sending an object to a controller from a th:each table
body: <p>I am making a table of experience data using the <strong>th:each</strong> attribute with <strong>Thymeleaf</strong> and my goal is to have a submit button in each row that, when clicked, will send an experience object to my controller that corresponds with the row I clicked the submit button in.</p>
  
  <p>I have no idea whats wrong and can't seem to find anything online to help with this problem.</p>
  
  <p>Here is my section of webpage code:</p>
  
  <pre><code>&lt;div th:unless="${#lists.isEmpty(borrower.experiences)}"&gt;
      &lt;h2&gt;List of Experiences&lt;/h2&gt;
      &lt;!--  &lt;form ACTION="#" th:action="@{/initiate-edit}" th:object="${experience}"
        method="POST"&gt;--&gt;
          &lt;table id="your-table-id"&gt;
            &lt;thead&gt;
              &lt;tr&gt;
                &lt;td&gt;Edit Buttons&lt;/td&gt;
                  &lt;th&gt;Date Planted&lt;/th&gt;
                  &lt;th&gt;Rating&lt;/th&gt;
                  &lt;th&gt;Category&lt;/th&gt;
                  &lt;th&gt;Dept&lt;/th&gt;
                  &lt;th&gt;Resolution&lt;/th&gt;
                  &lt;th&gt;Source&lt;/th&gt;
                  &lt;th&gt;Last Update Date&lt;/th&gt;
                  &lt;th&gt;Last Update Name&lt;/th&gt;
                  &lt;th&gt;Comment&lt;/th&gt;
              &lt;/tr&gt;
            &lt;/thead&gt;
            &lt;tbody&gt;
                &lt;tr th:each="experience : ${borrower.experiences}"&gt;       
                  &lt;td&gt;
                    &lt;form ACTION="#" th:action="@{/initiate-edit}" 
                      th:object="${experience}" method="POST"&gt;
                      &lt;!--&lt;a th:href="@{/initiate-edit/}"&gt;CLICK&lt;/a&gt;--&gt;
                      &lt;button type="submit"&gt;Submit&lt;/button&gt;
                    &lt;/form&gt;
                  &lt;/td&gt;
                  &lt;td th:text="${experience.experienceDate}"&gt;13/01/2014&lt;/td&gt;
                  &lt;td th:text="${experience.rating}"&gt;4&lt;/td&gt;
                  &lt;td th:text="${experience.categoryShortDesc}"&gt;Account and Billing&lt;/td&gt;
                  &lt;td th:text="${experience.deptDesc}"&gt;Account and Billing&lt;/td&gt;
                  &lt;td th:text="${experience.resolutionShortTx}"&gt;Account and Billing&lt;/td&gt;
                  &lt;td th:text="${experience.source}"&gt;Account and Billing&lt;/td&gt;
                  &lt;td th:text="${experience.lastUpdateDate}"&gt;Account and Billing&lt;/td&gt;
                  &lt;td th:text="${experience.lastUpdatedName}"&gt;Account and Billing&lt;/td&gt;
                  &lt;td th:text="${experience.commentsShort}"&gt;Account and Billing&lt;/td&gt;    
                &lt;/tr&gt;             
              &lt;/tbody&gt;
         &lt;/table&gt;    
  &lt;/div&gt;
  </code></pre>
  
  <p>Here is the method I am sending it to:</p>
  
  <pre><code>@RequestMapping(value = "/initiate-edit", method = RequestMethod.POST)
      public String initiateEdit(@AuthenticationPrincipal final User user, 
                                 @ModelAttribute("SpringWeb")CustomerExperience editableExperience, final Model model) {
  
          LOG.info("THIS IS A TEST!!!" + editableExperience.getSsn());
  
          model.addAttribute("editableExperience", editableExperience);
  
          return EDIT_PAGE;
  
      }
  </code></pre>