Spring MVC : Date problem fix

Add this following code to resolve the date problem in your controller


@InitBinder
     private void dateBinder(WebDataBinder binder) {
          // The date format to parse or output your dates
          SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
          // Create a new CustomDateEditor
          CustomDateEditor editor = new CustomDateEditor(dateFormat, true);
          // Register it as custom editor for the Date type
          binder.registerCustomEditor(Date.class, editor);
     }

Advertisements