I'd like to revive this topic - I face a similar problem, of supporting custom editors for a "date" and a "time". My approach was to use different classes for each, since the command object bean literally used java.util.Date for one and java.sql.Time for the other:
Code:
private static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
private static final DateFormat timeFormat = new SimpleDateFormat("h:mm a");
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
super.initBinder(request, binder);
CustomDateEditor cde = new CustomDateEditor(dateFormat, true);
binder.registerCustomEditor(java.util.Date.class, cde);
CustomDateEditor cte = new CustomDateEditor(timeFormat, true);
binder.registerCustomEditor(java.sql.Time.class, cte);
}
This actually worked when displaying the command object in a form. The date field appeared in the "date" format, the time field in the "time" format. So far so good.
The problem arose with form processing. Submitting exactly the values Spring populated into the form (ie. "2005-08-03" for date and "12:00 AM" for time), the date converts successfully, but the time gets "Failed to convert property value of type [java.lang.String] to required type [java.sql.Time] for property 'responseTime'"
So it would appear Spring does use the custom editors for getting both fields, but only for setting the "date" field. Any ideas why it can't convert the time?