我在JSP頁面上有單選按鈕。InitBinder不被調用/調用
<form:form modelAttribute="obj" action="save">
<form:radiobuttons path="person" items="${List}"/>
<form:button>Save</form:button>
</form:form>
列表:的人對象列表 的OBJ:
Class obj{
Person person;
getter/setters
}
在這JSP,我有當選擇特定單選按鈕附加的人。
在控制器端
@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對象的字符串...所以我得到的結合異常無法從字符串轉換成個人。
當將數據綁定到modelAttribute.Hence時,在initbinder中我會將字符串轉換爲Person對象之前調用InitBinder。
這裏主要的問題是我的InitBinder在Not called/Invoked。 請給我解決方案。
謝謝。
我也這樣做過,但沒有叫! –
你把斷點在binder.registerCustomEditor(Ob ....或setValue(text); – krishnakumarp
我在方法中使用System.Out void setAsText() –