I have radio button on JSP Page.
<form:form modelAttribute="obj" action="save">
<form:radiobuttons path="person" items="${List}"/>
<form:button>Save</form:button>
</form:form>
List : List of person Objects Obj :
Class obj{
Person person;
getter/setters
}
In that JSP, i have to append person when particular radio button selected.
On Controller side
@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);
}
});
}
Here i am using initbinder,because i am getting person object string from jsp...So i am getting binding exception that can not convert from String to Person .
InitBinder is called before when binding data to modelAttribute.Hence in initbinder i will conver string to Person object.
Here The main problem is That My InitBinder in Not called/Invoked . please give me solution.
Thank you.
Please check whether it is getting called by putting breakpoints or debug statements.
Your model attribute is named "obj". But in propertyeditor you've used "person" as property path.
Please try using "obj" as propertyPath or remove that parameter and use this signature. registerCustomEditor(Class requiredType, PropertyEditor propertyEditor)
Hope it helps.
黑暗中的狂野刺杀,是否从org.springframework.web.bind.annotation
导入正确的@InitBinder
?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.