I have the following (simplified to the bone) controller:
@Controller public class TestController { @RequestMapping(value = "/test.htm", method = RequestMethod.GET) public String showForm(final ModelMap map) { final TestFilter filter = new TestFilter(); filter.setStartDate(new Date(System.currentTimeMillis())); map.addAttribute("reportPerResourceForm", filter); return "test"; } @InitBinder public void initBinder(final WebDataBinder binder) { binder.registerCustomEditor(Date.class, null, new CustomDateEditor(new SimpleDateFormat("dd/MM/yyyy"), true)); }
}
jsp:
<form:form commandName="reportPerResourceForm" id="reportForm"> <form:input path="startDate" /> </form:form>
This is the controller that I quickly created to test the problem that I had with another controller. As you can see in the controller, CustomeDateEditor is defined. In my actual controller, this editor works fine; when you enter, for example, 11/01/2010 in the form field, it is beautifully converted to Date by the editor; also, returning to the form, the date is again beautifully converted back to a string.
However, when I (as in TestController) want to set the default date on the form, then it simply displays Date.toString () in the form field instead of using the return value from CustomDateEditor.getAsText ()! After some debugging, I found out that my InitBinder method is not called when RequestMethod == GET. This is normal?
I'm sure I can get around this without using
Thank you for your help,
Stein
source share