在Request
调用loadForm
中填充时,弹出表单无法成功提交[给出绑定问题],但在使用setupFormObject
的方法@ModelAttribute
中填充时效果正常注释标记。我可以在github中提供一个简单的例子来测试是否要求:)
我花了几天时间搜索甚至使用AutoPopulatingList,但无济于事
以下示例
@ModelAttribute("showForm")
public ShowForm setupFormObject() {
//Instantiate showForm with data
return showForm;
}
@RequestMapping(method = RequestMethod.GET)
public ModelAndView loadForm(@RequestParam("id") String id, HttpSession session) {
ModelAndView modelAndView = new ModelAndView(nextPage);
//Instantiate showForm with data
//modelAndView.addObject("showForm", showForm);
return modelAndView;
}
@RequestMapping(method = RequestMethod.POST)
public String post(@ModelAttribute("showForm") ShowForm showForm, BindingResult result, final RedirectAttributes redirectAttrs) {
//I see changed data here in showForm when populated using @setupFormObject
//See an exception in JSP with binding error if populated in loadForm
return "";
}
非常感谢您的帮助
由于
答案 0 :(得分:0)
将@ModelAttribute
添加到showForm
类型为ShowForm
的参数中,该参数将传递给loadForm
方法。
@RequestMapping(method = RequestMethod.GET)
public ModelAndView loadForm(@RequestParam("id") String id,
@ModelAttribute("showForm") ShowForm showForm, HttpSession session) {
ModelAndView modelAndView = new ModelAndView(nextPage);
//Instantiate showForm with data
//modelAndView.addObject("showForm", showForm);
return modelAndView;
}
另外请确保您确实在执行GET请求,我怀疑这可能是一个帖子,这需要:
@RequestMapping(method = RequestMethod.POST)
public ModelAndView loadForm(@RequestParam("id") String id,
答案 1 :(得分:0)