【发布时间】:2013-12-31 06:49:31
【问题描述】:
我正在尝试使用 Thymeleaf 和 Spring MVC 处理表单。 用户应该选择一个预订,然后将其保存在表单中。
模板如下所示:
<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>
我想保存保留对象以便在另一个视图中使用它 (checkin_test)。这不起作用,因为预订对象始终为空。
控制器如下所示:
@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";
}
表格很简单:
public class ReservationSelectionForm {
private Reservation reservationSelection;
@NotEmpty
private String firstname;
@NotEmpty
private String lastname;
//getter & setter
如果我尝试使用表单设置名字,则名字完全可以包含在 ReservationSelectionForm 中。
当我传递整个 Reservation 对象 (th:value="${reservation}") 时,ReservationSelectionForm 中始终是 null。
有人可以向我解释和/或帮助我传递整个预订对象吗?
【问题讨论】:
标签: java forms spring-mvc thymeleaf