problems with custom editors
Hi,
I'm seeing a strange problem here with a custom editor I set in the initBind() method of my SimpleFormController. The editor is registered properly and also used when showing the form for the first time (debugging showed that its getValue is accessed). On submitting the form the editors setValue() function is also accessed, but rendering the result view it seems the editor is not used anymore to get the value again.
In my case I've created a custom date editor (CustomDateEditor from spring doesn't do what I need) and registering it for 2 properties of the command object in initBind(): MyDateEditor cde = new MyDateEditor( r.getLocale(), true ); b.registerCustomEditor( Date.class, quot;aufnahmedatum_bisquot;, cde ); MyDateEditor cde2 = new MyDateEditor( r.getLocale(), false ); b.registerCustomEditor( Date.class, quot;aufnahmedatum_vonquot;, cde2 );
And on the result view the value from that field is not formatted according to the format of the editor, but using DateFormat.FULL (as far as I can see).
Has anybody ever seen something like that? (I'll see to produce a small self-contained example, but that might take a while)
The key is to use errors.getModel() in your controller as the model returned in the ModelAndView. Reason being, errors.getModel() will have the necessary propertyEditors attached to it whereas returning a new map containing your command object will not.
Aaah, interesting. I was using onSubmit() for the logic and then created a ModelAndView instance with just the command object.
Changing to doSubmitAction it works fine |