Hello I have a problem with Spring MVC 3.0 + CustomDateEditor and one field of type java.util.Date In my controller I have :
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
DateFormat df = new SimpleDateFormat("hh:mm MM/dd/yyyy");
df.setLenient(false);
CustomDateEditor editor = new CustomDateEditor(df, false);
binder.registerCustomEditor(Date.class, editor);
}
Than when the user types some date using this pattern example "10:10 10/10/2009" the form is validated correctly and is submitted BUT if there are other validation errors the form is shown again and the value of the "date" textfield looks like: Sat Oct 10 10:10:00 CEST 2009. Why it displays this instead of the "10:10 10/10/2009" ? is this a bug or? Any ideas ?
If I am correct there are 2 methods in the CustomDateEditor. This one :
public String getAsText(){
Date value = (Date)getValue();
return ((value != null) ? this.dateFormat.format(value) : "");
}
Which maybe should be called when the date object is asked for a text value. and the other one :
public void setAsText(String text) throws IllegalArgumentException
I think that only one of them is invoked for some reason and the other one is not invoked dont know why. Any ideas ? my form looks just like that :
<form:form id="appointmentForm" name="appointmentForm" commandName="appointmentForm" method="GET" action="submitAppointment.action">
...
<td colspan="3">[MOCKUP(hh:mm MM/dd/yyyy)] <form:input path="appointmentDate"/> <form:errors path="appointmentDate"/> </td>
...