A basic property editor for java.util.Dates can be wired in like
Code:
protected void initBinder(HttpServletRequest request,
ServletRequestDataBinder binder) throws Exception
{
String dateFormat = getMessageSourceAccessor().getMessage("format.date",
"dd.MM.yyyy");
SimpleDateFormat df = new SimpleDateFormat(dateFormat);
df.setLenient(true);
binder.registerCustomEditor(java.util.Date.class, new CustomDateEditor(
df, true));
}
I suspect you might need to create a new property editor. You might be able to write a simple CustomSqlDateEditor although I have not done that before. Custom editors are pretty simple once you get your head around the idea. (took me a while tho :-)
Something as basic as the following might work.
Code:
public class CustomSqlDateEditor extends PropertyEditorSupport
{
DateFormat format = null;
public CustomSqlDateEditor(DateFormat format)
{
super();
this.format = format;
}
public String getAsText()
{
java.sql.Date value = (java.sql.Date) getValue();
return (value != null ? this.format.format(new java.util.Date(value.getTime())) : "");
}
public void setAsText(String text) throws IllegalArgumentException
{
try {
setValue(new java.sql.Date(this.format.parse(text).getTime()));
}
catch (ParseException e) {
throw new IllegalArgumentException("Could not parse date: "
+ e.getMessage());
}
}
}
FWIW: I would not expose java.sql.Date in my domain/form code anyway, I would expose java.util.Date which has better support (IMHO).