Spring MVC表单(JSP)中组合框中的java默认选中选项
Design a form(<spring:form></spring:form>) in JSP using Spring MVC architecture
从控制器枚举。值在模型属性中绑定
查看我用来绑定combo值和默认选定值列表的代码
m.addAttribute("questTypes", Enum.values());
m.addAttribute("defsel", Enum.Value1.getName());
然后在JSP页面上编写以下代码
<form:select path="otquestion.otQuestionId" class="combobox required" style="float:left;" id="selectQuestid">
<form:option label="Select Question Type..." value=""></form:option>
<form:options items="${questTypes}" selected="${defsel}" itemLabel="name" itemValue="value"></form:options>
</form:select>
最后列表出现了,但组合的默认选择不起作用。请帮忙
# 1 楼答案
我通过以下绑定path=“otquestion.otquestion-id”的值得到答案。 在otquestion对象otquestion ID成员变量中,设置值并在model object的帮助下返回该对象