0

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

1 回答 1

1

我认为您的属性名称错误,应该itemValue不是itemsValue

<form:options items = "${gender.genderList}" itemValue="genderId" itemLabel="genderDesc" />
于 2012-09-02T22:33:09.490 回答