Hi, Gentlemen.
I need Your help with the following (I work with Spring 3):
there's a Controller, e.g. SubmitSomeRequestController (it doesn't extend a spring's base class ->Spring 3 doesn't require that):
@Controller
public class SubmitSomeRequestController {
@InitBinder
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) {
MyCustomBoolPropEditor editor = new MyCustomBoolPropEditor();
binder.registerCustomEditor(Boolean.class, "boolField1", editor);
binder.registerCustomEditor(Boolean.class, "boolField2", editor);
}
@RequestMapping(method = RequestMethod.POST, value="someUrlOfMine/htmPageName.htm")
public ModelAndView createTheDesiredObject(
HttpServletRequest request) {
Map<String, String[]> params = request.getParameterMap();
boolean field1 = Boolean.parseBoolean( params.get("boolField1")[0] );
boolean field2 = Boolean.parseBoolean( params.get("boolField2")[0] );
//retrieve any other params from Request
//do some othe sexy stuff concerned with setting/populating appropriate Objects' fields
ModelAndView mav = buildMavForCheckRequest(...);
return mav;
}
}
What I expect/wanna to have via using the mentioned above? I want Spring to convert automatically those boolField1/boolField2 etc. from String "true" to true of type boolean (yes, setAsText/getAsText in MyCustomBoolPropEditor are properly implemented). And I EXPECT that conversion already done when createTheDesiredObject() method is invoked, but meanwhile request contains String parameters, so what do I do wrong (or rather how should I implement the method to make Spring do the conversion automatically for me)??? There's one more implication:
the form's fields represent different Objects' fields, so I tried to specify the handling method in my Controller like this:
@RequestMapping(method = RequestMethod.POST, value="someUrlOfMine/htmPageName.htm")
public ModelAndView createTheDesiredObject(HttpServletRequest request, DataBinder binder) {
//...
}
but the above seems incorrect as in case of using DataBinder I have to point out the @ModelAttribute, but I have several objects, who's fields have to be populated from the submitted form's values, so using the @ModelAttribute seems incorrect to me, pls correct me if I'm wrong..
Perhaps I have to implement some other method to get Spring do the trick - convert automatically String "true" to Boolean type?? Or do I have to change the createTheDesiredObject() method mentioned above for the conversion to work?
Any help with the above (perhaps I missed smt substantial concerning the propEditors' conversion) or explanations how it works would be highly appreciated (sure, I've read appropriate Spring's reference docs and googled a lot, but meanwhile still can't get it work as expected).
Gents, thanks in advance for help/hints.


).
Reply With Quote
...