SpringMVC ListBox人口

时间:2012-09-02 20:28:56

标签: java jsp spring-mvc listbox controller

我有一个列表框,当我运行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>

1 个答案:

答案 0 :(得分:1)

我认为你的属性名称有误,应该是itemValue而不是itemsValue

<form:options items = "${gender.genderList}" itemValue="genderId" itemLabel="genderDesc" />