0

I want to bind date and time separately in a controller. I have 1 timepicker and 1 datepicker on a form, i use InitBinder binder for time picker which is,

@InitBinder
    public void initBinder(WebDataBinder binder) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        sdf.setLenient(true);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, true));
    }

But this doesn't work for both time picker and date picker. any better suggestion please....

1 Answers1

0

Try this with your code:

@InitBinder
void allowFields(WebDataBinder webDataBinder){
    webDataBinder.setAllowedFields("date"); 
    webDataBinder.setAllowedFields("time");
}

and use this in your POJO:

  @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
  private Date date;
Devendra Singh
  • 640
  • 6
  • 12