SpringMVC Custom Collection Editor Not Returning Data To Jsp

前端 未结 1 1130
醉酒成梦
醉酒成梦 2020-12-12 01:54

I am binding a multi select list in spring the item does not get its data from the DAO the data is added from another select option list. The user clicks a button and the da

相关标签:
1条回答
  • 2020-12-12 02:21

    The Solution to this issue was very simple all of the work was already done in the CustomCollectionEditor. This is important when binding complex data types such as above. There may be other approaches to doing this however i find this to be a very clean and simple approach.

    The return statement is very important since it binds to the item attribute of the element in the view. CustomCollectionEditor return a list of objects (victims) The use of the DAO gets the object from the database. This is important since the post only sends the select value not the label, hence we reconstruct the list and resend to the view.

    The part of this that i omitted was passing the List Object from the controller back to the view.

    Controller

    @RequestMapping(value="save.htm", method = RequestMethod.POST)
        public ModelAndView handleSave(@Valid @ModelAttribute Crime crime, 
        BindingResult result,
        ModelMap m,
        Model model) throws Exception {
    
    
        if(result.hasErrors()){
               model.addAttribute("victimList",crime.getVictims());
    
        return new ModelAndView("*Your View*");
    ...............
    
    0 讨论(0)
提交回复
热议问题