Reputation: 3510
I have a date input field in my jsp like this:
<form:input name="inputDate" id="inputDate" value="" path="date"/>
This form is mapped to a @ModelAttribute
account
which has the date defined like this:
private java.util.Date date ;
When I submit the form, I get an error (of course) that says:
Failed to convert property value of type java.lang.String to required type java.util.Date ...
Please suggest a way I can parse date
in the JSP itself, so that the @ModelAttribute
can directly set the date
field with the value
Upvotes: 0
Views: 1559
Reputation: 28005
Just register binder in your @Controller
like in this example:
@Controller
public class MyFormController {
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class,
new CustomDateEditor(dateFormat, false));
}
// ...
}
Upvotes: 1