我正在使用这样的表单支持bean。表单支持bean不保留已设置的属性值
public class BeanData implements Serializable{
private String param1;
private String param2;
private String param3;
private String param4="india";
getters setters
}
然后再送bean对象的模型如下─
@RequestMapping(value=/formPage, method={RequestMethod.GET,RequestMethod.POST})
public ModelAndView getPage(HttpSession session, ModelAndView modelAndView) {
BeanData formBean = new BeanData();
formBean.setParam2("123456"); // this param2 doens't have any field in JSP
modelAndView.addObject("formBean", formBean);
modelAndView.setViewName(PAGE);
return modelAndView;
}
@RequestMapping(value=submitData, headers="Accept=*/*", method={RequestMethod.POST})
public void submitData(@Valid @ModelAttribute("formBean") BeanData formBean, BindingResult result, HttpServletRequest request,HttpServletResponse response,ModelAndView modelAndView, HttpSession session) {
LOGGER.info("param1:"+formBean.getParam1()); // Param1 has a path map in jsp field. So whatever user is puuting into form field, that is getting populated here
LOGGER.info(" param2:"+formBean.getParam2()); // It has not been used in JSP. Though from controller it was populated before sending the bean to the jsp. but here the value is null . This is the concern
LOGGER.info("param3:"+formBean.getParam3());// Param1 has a path map in jsp field. So whatever user is puuting into form field, that is getting populated here
LOGGER.info("param4:"+formBean.getParam4());//thsi field also has not been used in JSP. But this property was set in bean instantiation. It is also getting retrieved successfully.
modelAndView.setViewName(SUCCESS PAGE);
}
我担心的是,我想用setter方法来设置一个bean属性,并希望豆后盾对象传递给JSP。然后,所有的属性值应该绑定(我明确地绑定使用表单提交路径属性和我已经创建了bean对象时已经设置)到后台对象,它应该在控制器中接收。请指导我在哪里做错了。
<form:hidden path="formBean.param2"/>
它不会显示在:
您是否要在提交表单后检索设置为'param2'的值? – VPK