1

I am trying to use type=Date in my JSP page to parse the date to the controller. But I am getting syntactically incorrect data (400 error). I tried my best to find the solution but failed to get the proper one. Please help me to solve this. Any suggestions would be appreciated.

My domain class:

public class Doctor{  
     @DateTimeFormat(pattern = "MM-DD-YYYY")
     private Date dateOfBirth=null;

     // Setter and Getter
}

JSP code:

<f:input path="dateOfBirth" type="Date"/>

I tried using the @InitBinder in contoller as well, but could not succeed.

Ali Dehghani
  • 46,221
  • 15
  • 164
  • 151
Manju
  • 103
  • 2
  • 14

2 Answers2

0

You might want to take a look at this question, where the most voted answer suggests the use of JSTL <fmt:formatDate>.

Community
  • 1
  • 1
marcelovca90
  • 2,673
  • 3
  • 27
  • 34
  • That question link was for getting the value from the backend. I am looking for setting from front end. :-( – Manju Oct 26 '16 at 12:00
0

I try to run your code and an exception happens. The cause comes from where date format on jsp page is not same as format on java bean. Let's change this format

@DateTimeFormat(pattern = "MM-DD-YYYY")
private Date dateOfBirth=null;

to

@DateTimeFormat(pattern="yyyy-MM-dd") 
private Date dateOfBirth=null;

then this problem is resolved

David Pham
  • 1,673
  • 19
  • 17