开发者

listbox null after a post

with spring 3.0

when i click to submit information (post) this method is called here

@RequestMapping(method = RequestMethod.POST)
public String userResult(@ModelAttribute UserForm userForm, Model model) {

   开发者_如何学编程 List<UserInfo> listUserInfo = userService.searchUserInfo(userForm.getsearchCriteria());
    userForm.setListUserInfo(listUserInfo);
    userForm.setSearchDone(true);
    model.addAttribute(userForm);

    return "userSearch";
} 

the jsp have many listbox, when i check the userForm and model, all listbox is null... is there a way to avoid that? because i will need to do some call to db every time

thanks


You can use @ModelAttribute in a controller method in this way.

public class YourController{
    @ModelAttribute("list1")
    public List<YourObject> retrieveList1(){
         //retrieve here the list from database
         return list1;
    }

    public String userResult(@ModelAttribute UserForm userForm, Model model) {
        ...
    }
}

When you annotate the method with @ModelAttribute("list1") then this method will automatically be executed before any method in the controller and then the result will be added in the model at "list1". You can set list1 to the value property you need and add as many @ModelAttribute annotated controllers as you need.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜