-4
  1. I wanted to bind the spring date field to the pojo class and return the date
  2. The dateOfbirth is of type java.sql.Date . Now when i pass the date from spring form to the function setDateOfBirth ,it is taking null value

For example in register.jsp (Registration form) I have the particular field

<form:label path="DateOfBirth">DateOfBirth</form:label>
<form:input path="DateOfBirth" type="date"/>

Register.java (Pojo class)

 public void setDateOfBirth(Date dateOfBirth) {
   this.dateOfBirth = dateOfBirth   ;
 }

 public void getDateOfBirth() {
   return this.dateOfBirth;
 }

when I call getDateOfBirth()
returns: Sat Dec 12 00:00:00 IST 1992

Input :- 12/12/1992

Expected Output :- 12/12/1992

What I get: null

Please help me how to convert this ?

James92
  • 81
  • 2
  • 8
  • 1
    Possible duplicate of [spring mvc date format with form:input](http://stackoverflow.com/questions/18163404/spring-mvc-date-format-with-forminput) – Kannan Thangadurai Nov 17 '15 at 07:57
  • you should be using a String rather than date in that case as for Date it should be date not some formatted Date. To get formatted date use SimpleDateFormat or jstl tags on views. – Vinay Prajapati Nov 17 '15 at 08:01
  • In the link http://stackoverflow.com/questions/18163404/spring-mvc-date-format-with-forminput Result is in format : Sat Dec 12 00:00:00 IST 1992 . But i want the result in 12/12/1992 – James92 Nov 17 '15 at 08:10

1 Answers1

0

Try to add @DateTimeFormat(pattern = "dd/MM/yyyy") to your dateOfBirth in Register.java

@DateTimeFormat(pattern = "dd/MM/yyyy")
private Date dateOfBirth;
codeaholicguy
  • 1,671
  • 1
  • 11
  • 18
  • I wanted to insert sql date . so i defined dateOfBirth in Register.java as java.sql.Date . When i call getDateOfBirth() , it gives me null . – James92 Nov 17 '15 at 09:13