Spring Init Binder

springmvc

// Spring MVC - initBinder:

initBinder tells Spring MVC to consistently use a particular format. We can specify the format in each 
individual places:

<fmt:formatDate pattern="dd/MM/yyyy" value="${todo.targetDate}" />

Alternatively,  we can use InitBinder to consistently format it across the application.

@InitBinder
protected void initBinder(WebDataBinder binder) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
    binder.registerCustomEditor(Date.class, new CustomDateEditor(
            dateFormat, false));
}

We added the above method to our controller.  With this code, we register 
the custom editor for the Date.class.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License