简体   繁体   English

Spring MVC Form(JSP)组合框中的默认选定选项

[英]Default selected option in combo box in Spring MVC Form(JSP)

 Design a form(<spring:form></spring:form>) in JSP using Spring MVC architecture

From Controller Enum.values bind in model attribute 从控制器枚举值绑定模型属性

Look the code what i am using to bind the list of value of combo and default selected value. 看一下我用来绑定组合值列表和默认选定值的代码。

  m.addAttribute("questTypes", Enum.values());

  m.addAttribute("defsel", Enum.Value1.getName());

Then on JSP page write this code 然后在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>

Finally list is came but default selection of combo is not working. 终于有了列表,但是组合的默认选择不起作用。 Please help 请帮忙

I get the answer by following bind the value of path="otquestion.otQuestionId". 我通过绑定path =“ otquestion.otQuestionId”的值来得到答案。 In otquestion object otQuestionId member variable set the value and return that object with the help of model object. 在otquestion对象中,otQuestionId成员变量设置值并在模型对象的帮助下返回该对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM