我在JSP页面上有单选按钮。
<form:form modelAttribute="obj" action="save">
<form:radiobuttons path="person" items="${List}"/>
<form:button>Save</form:button>
</form:form>List : person Obj:
Class obj{
Person person;
getter/setters
}在那个JSP中,当选择特定的单选按钮时,我必须附加person。
在控制器侧
@RequestMapping(value = "/save", method = RequestMethod.POST)
public String postProcess(@ModelAttribute("obj") Obj obj,BindingResult error) {
//processing
return "anotherJsp";
}
@InitBinder
public void initBinder(WebDataBinder binder, Locale locale, HttpServletRequest request) {
binder.registerCustomEditor(Obj.class,"person", new PropertyEditorSupport() {
@Override
public void setAsText(String text) {
//processing for conversion of person object String to Person Object
setValue(text);
}
});
}这里我使用initbinder,因为我从jsp...So获得person对象字符串,所以我得到了绑定异常,它不能从字符串转换为Person。
以前,当将数据绑定到InitBinder中的initbinder时,我将将字符串传递给Person对象。
这里的主要问题是我的InitBinder中没有调用/调用。请给我解决办法。
谢谢。
发布于 2013-08-29 05:04:13
请通过放置断点或调试语句检查它是否正在被调用。
您的模型属性名为"obj“。但是在propertyeditor中,您使用了"person“作为属性路径。
请尝试使用"obj“作为propertyPath或删除该参数并使用此签名。registerCustomEditor( requiredType类,PropertyEditor propertyEditor)
希望能帮上忙。
发布于 2013-10-16 14:48:03
在黑暗中狂野刺伤,它从org.springframework.web.bind.annotation导入正确的org.springframework.web.bind.annotation吗?
https://stackoverflow.com/questions/18502560
复制相似问题