我有一个列表框,我在运行UI时从数据库中填充,我能够看到itemLabel,但不能看到itemsValue,运行页面时看到的代码是:
<li>
<label>Select Gender</label>
<select id="genderId" name="genderId">
<option itemsValue="genderId" value="com.crimetrack.business.Gender@1a81bd5">Select Gender</option><option itemsValue="genderId" value="com.crimetrack.business.Gender@1bb60ad">FEMALE</option><option itemsValue="genderId" value="com.crimetrack.business.Gender@c80e21">MALE</option>
</select>
</li>
我没有正确显示值,但显示了说明。
@Controller
................
private GenderManager genderManager;
Map<String, Object> myGender = new HashMap<String, Object>();
.........
@RequestMapping(value="officer_registration.htm", method = RequestMethod.GET)
public ModelAndView loadPage(HttpServletRequest request,
HttpServletResponse response,@ModelAttribute Officers officer, BindingResult result, ModelMap m, Model model) throws Exception {
try{
myGender.put("genderList", this.genderManager.getGenderList());
model.addAttribute("gender", myGender);
return new ModelAndView("officer_registration");
}catch(Exception e){
request.setAttribute("error",e.getMessage());
return new ModelAndView("error_page");
}
}
public void setGenderManager(GenderManager genderManager){
this.genderManager = genderManager;
}
jsp
<li>
<label>Select Gender</label>
<form:select path="genderId">
<form:options items = "${gender.genderList}" itemsValue="genderId" itemLabel="genderDesc" />
</form:select>
<form:errors path="genderId"/>
</li>
最佳答案
我认为属性名称错误,应为itemValue
而不是itemsValue
<form:options items = "${gender.genderList}" itemValue="genderId" itemLabel="genderDesc" />