I have a table showing testResults using thymeleaf template -
<tr th:each="testResult,iterationStatus : ${testResults}">
<td th:text="${iterationStatus.count}">1</td>
<td th:text="${testResult.name}">DOMAIN</td>
<td th:text="${testResult.length}">PROCESS</td>
<td>
<form ACTION="#" th:action="@{/deleteName}" th:object="${testResult}" method="POST">
<input type="hidden" th:field="*{name}"/>
<input type="hidden" th:field="*{length}"/>
<button type="submit">submit</button>
</form>
</td>
</tr>
name and length are showing fine in the html, but when i submit the form, controller gets name and length as empty values. What i am doing wrong in assigning the values....
below is controller method that gets invoked -
@RequestMapping(method= RequestMethod.POST, value = "/deleteName")
public String deleteName(@Valid @ModelAttribute("testResult") TestResult testResult, BindingResult bindingResult, Model model, HttpServletRequest request) {
System.out.println(testResult.toString());
return "/";
}
output once i submit the form -
TestResult [name=, length=, xyz=null]
I couldn't get
th:field
to work inside ath:object
, like you're doing here. However, if I stop usingth:field
, and useth:value
instead, the form submits successfully.