Back Forum Reply New

Unable to bind Dates from form

Hi all
I have a simple newbie question

I took this sample code:
blogs/2010/07/...ing-forms.htmlCode:
@RequestMapping(value = quot;/addContactquot;, method = RequestMethod.POST)
public String addContact(@ModelAttribute(quot;contactquot;)
Contact contact, BindingResult result) {

System.out.println(quot;First Name:quot; + contact.getFirstname() +
quot;Last Name:quot; + contact.getLastname());

return quot;redirect:contacts.htmlquot;;
}
I added date field to the Contact object and to the UICode:
lt;tdgt;lt;form:label path=quot;birthDatequot;gt;Birth Datelt;/form:labelgt;lt;/tdgt;
lt;tdgt;lt;form:input path=quot;birthDatequot; /gt;lt;/tdgt;
After submiting the new  contact I am getting all fields except the Date fields  in the addContact method  (including other new fields I added)

There is a conversion error:

Code:

Failed to convert property value of type java.lang.String to required type java.util.Date for property birthDate;
nested exception is java.lang.IllegalStateException:
Cannot convert value of type [java.lang.String] to required type [java.util.Date] for property birthDate:
no matching editors or conversion strategy found
Where can I specify that birthDate input is date type?
Thank you very much

I've the same problem.

You has specify birthDate as a Date in your Command object (Contact).

In my controller I added the InitBinder but I still have the same problemCode:
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat(quot;dd/MM/yyyyquot;);
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
}childmetal were you able to find a solution?
¥
Back Forum Reply New