I'm trying to process a form with Thymeleaf and Spring MVC. The user should select a reservation, which is then saved in the Form.
The Template looks like this:
<form action="#" th:object="${reservationselectionform}">
<select th:field="*{reservationSelection}" class="selectpicker" data-live-search="true" style="display: none;" >
<option th:each="reservation : ${reservationlist}"
th:value="${reservation}"
th:text="${reservation.user.userAccount.firstname}">Tyler Durden</option>
</select>
<button type="submit" class="btn btn-primary" formaction="/checkintest" formmethod="post">Weiter</button>
I want to save the reservation object to work with it in another view (checkin_test). This doesn't work, as the reservation object is always null.
The controller looks like this:
@RequestMapping(value="choose_reservation", method = RequestMethod.GET)
public String chose_reservation(ModelMap modelMap{
modelMap.addAttribute("reservationselectionform", new ReservationSelectionForm());
return "checkin/choose_reservation";
}
@RequestMapping("/checkintest")
public String personaldata (ModelMap modelMap,
@ModelAttribute("reservationselectionform") ReservationSelectionForm reservationSelectionForm){
return "checkin/checkintest";
}
The form is as simple as:
public class ReservationSelectionForm {
private Reservation reservationSelection;
@NotEmpty
private String firstname;
@NotEmpty
private String lastname;
//getter & setter
If I try setting the firstname using the form, the firstname is included in the ReservationSelectionForm perfectly fine.
When I pass the whole Reservation object (th:value="${reservation}")
, it is always null
in the ReservationSelectionForm.
Can someone explain this to me and/or help me to pass the whole reservation object?
Your select list is always empty.
<option th:each="reservation : ${reservationlist}"
reservationlist is never added to model so th:each
is iterating null
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.