Java 未调用/调用InitBinder
我在JSP页面上有单选按钮Java 未调用/调用InitBinder,java,spring,spring-mvc,Java,Spring,Spring Mvc,我在JSP页面上有单选按钮 <form:form modelAttribute="obj" action="save"> <form:radiobuttons path="person" items="${List}"/> <form:button>Save</form:button> </form:form> 在该JSP中,我必须在选中特定单选按钮时追加person 在控制器端 @RequestMapping(v
<form:form modelAttribute="obj" action="save">
<form:radiobuttons path="person" items="${List}"/>
<form:button>Save</form:button>
</form:form>
在该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获取person对象字符串……所以我获取的绑定异常,无法从字符串转换为person
在将数据绑定到modelAttribute之前调用InitBinder。因此,在InitBinder中,我将把字符串转换为Person对象
这里的主要问题是我的InitBinder in没有被调用。
请给我一个解决方案
谢谢。请检查是否通过放置断点或调试语句调用它 您的模型属性名为“obj”。但在propertyeditor中,您使用了“person”作为属性路径 请尝试使用“obj”作为propertyPath,或删除该参数并使用此签名。
希望有帮助。请检查是否通过放置断点或调试语句调用它 您的模型属性名为“obj”。但在propertyeditor中,您使用了“person”作为属性路径 请尝试使用“obj”作为propertyPath,或删除该参数并使用此签名。
希望有帮助。黑暗中的狂野刺杀,是否从
org.springframework.web.bind.annotation
导入了正确的@InitBinder
?黑暗中的狂野刺杀,是否从org.springframework.web.bind.annotation导入正确的@InitBinder
?是否将断点放在binder.registerCustomEditor(Ob…或setValue(text)上;我正在使用System.Out in方法void setAsText()将其作为公共void InitBinder(…)的第一行方法。查看它是否正在打印…不,它不是打印您是否在binder.registerCustomEditor(Ob…)或setValue(text)处放置断点;我正在使用System.Out方法void setAsText()将其作为公共void initBinder(…)方法的第一行。查看它是否正在打印…不,它不是打印
@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);
}
});
}