I am making a table of experience data using the th:each attribute with Thymeleaf and my goal is to have a submit button in each row that, when
I had the same problem. What @Aeseir said it has helped me, but instead of :
<input type="hidden" th:field="*{experienceDate}"/>
I needed to use:
<input type="hidden" th:value="${experience.experienceDate}" name="someName"/>
As @Aeseir's answer, you need to pay attention to the th:object
and th:field
The field
can be int, double, String, List and the object should have getter and setter for its field.
In this case
public class Experience{
String field;
List<String> list;
//getter() and setter()
}
You need to fill your form with inputs as the inputs get sent:
<form ACTION="#" th:action="@{/initiate-edit}" th:object="${experience}" method="POST">
<input type="hidden" th:field="*{experienceDate}"/>
<input type="hidden" th:field="*{rating}"/>
<!-- ADD ALL THE OTHER FIELDS THAT ARE PART OF THE OBJECT -->
<button type="submit">Submit</button>
</form>
This will hide your object data from user but when they click on submit, it will send the object data as required (rather than having empty form sent as you have it currently).