Im trying to create a loop using th:each on a list object and so creating like 10 forms binding different objects. As far without success.. is it even possible? if not.. do you have an idea how to dynamically bind an object to forms in a similar way for objects in a list?
This is what i tried..
@RequestMapping(value = "/area")
public String index(@AuthenticationPrincipal User currentUser, Model model) {
/* getPersons() returns an object list of diferent persons */
model.addAttribute("personslist", currentUser.getPersons());
return "area";
}
Thymleaf / html:
<div th:each="person: ${personslist}">
<form th:object="${person}" th:action="@{/fooBar}" method="post">
<input hidden="hidden" th:field="${person.id}"/>
//Other input fields...
<button type="submit"></button>
</form>
</div>