给定以下内容,如何绑定以下引导列表选择器?我从控制器传递到 index.jsp 的视图模型中填充了选择列表。但是,绑定似乎有很多变化。
class viewModel {
List<String> theList; // <- populated in my GET controller code
String selectedListItem; // <- trying to figure out how to get selected list item?
o o o
// assume get/set
}
index.jsp:
(我在提交按钮单击时得到了回发,我可以访问视图模型,但只需要弄清楚如何从列表中获取所选项目。)
<form class="form-horizontal" action="myController/indexSubmit" method="post">
<select class="form-control" placeholder=".input-medium" height>
<c:forEach items="${viewModel.gettheList()}" var="item" varStatus="count">
<option value="${count.index}">${item }</option>
</c:forEach>
</select>
<button type="submit" class="btn btn-primary btn-medium">Submit</button>
</form>
控制器:
@RequestMapping(value="indexSubmit", method = RequestMethod.POST)
public String indexSubmit(@ModelAttribute("viewModel") viewModel viewModel, ModelMap model) {
String item = viewModel.getselectedListItem(); // <- How can I pass this in?
System.out.println("Selected Item: " + item);
return "myController/index"; // <- want to add as query param: ?item=theItem
}