I am trying to make for each object in my list modal that contains a form with that object data.
So I have in my controller:
model.addAttribute("eventsInList", eventsInList);
and in my ThymeLeaf template:
<div th:each="evnt,intr : ${eventsInList}">
<div class="modal fade" th:id="'modal-' + ${evnt.getId()}">
// some content
<form th:action="@{/updateEvent}" th:object="${evnt}" method="POST">
<input type="text" class="form-control pull-right datepicker"
th:value="${evnt.getDate()}"
th:field="*{date}">
</form>
</div>
</div>
When I run this code it throws:
Neither BindingResult nor plain target object for bean name 'evnt' available as request attribute
So I tried this:
controller:
model.addAttribute("eventsInList", eventsInList); // list of CalendarEvent
model.addAttribute("editEvent", new CalendarEvent());
ThymeLeaf template:
<div th:each="evnt,intr : ${eventsInList}">
<div class="modal fade" th:id="'modal-' + ${evnt.getId()}">
// some content
<form th:action="@{/updateEvent}" th:object="${editEvent}" method="POST">
<input type="text" class="form-control pull-right datepicker"
th:value="${evnt.getDate()}"
th:field="*{date}">
</form>
</div>
</div>
This case does not throw any exception, but th:value="${evnt.getDate()}" is null
And confusing for me is that the row <div class="modal fade" th:id="'modal-' + ${evnt.getId()}"> normally works.
So is there any solution for this problem?
Thanks for your help all :)