Announcement Announcement Module
No announcement yet.
Why I need to register CustomDateEditor in the controller? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Why I need to register CustomDateEditor in the controller?

    my controller
    public class UsersController extends MultiActionController {
    	protected void bind(HttpServletRequest request, Object command)
    			throws Exception {
    		ServletRequestDataBinder servletRequestDataBinder = createBinder(
    				request, command);
    		DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
    				"dateFrom", new CustomDateEditor(dateFormat, true));
    		bindingResult = servletRequestDataBinder.getBindingResult();
    and when I fiiled my jsp form the date is correct parse. OK. But in the book "Spring in Action" is write: "Note that many of the custom editors that come with Spring (such as URLEditor,CustomDateEditor) are already registered with the bean factory upon container startup. You do not need to register them yourself using CustomEditorConfigurer."
    Than why I need to register CustomDateEditor in the my override method bind ?

  • #2
    Because CustomDateEditor is not preregistered by Spring.

    In the book "Java Development with the Spring Framework" by Rod Johnson et al it is explicitely mentioned that CustomDateEditor "is available to be registered (...) and used as needed by users".

    You can also look at the source code of PropertyEditorRegistrySupport. You will see that CustomDateEditor ist not among the default editors.

    In my opinion it would also not make sense to preregister a CustomDateEditor because of the different date formats that are used worldwide.