PDA

View Full Version : CustomEditor for java.sql.Date ?


jimdier
Nov 26th, 2004, 11:04 AM
I have a JSP that binds to a data bean.

In that data bean, I have a java.util.Date attribute and a java.sql.Date attribute.

My initBinder is as follows:

protected void initBinder (
HttpServletRequest request, ServletRequestDataBinder binder) {


SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, null, new
CustomDateEditor(dateFormat, true));
binder.registerCustomEditor(java.sql.Date.class, null, new
CustomDateEditor(dateFormat, true));
}


The java.util.Date attribute passes, but the java.sql.Date attribute doesn't, as I continually get:

Failed to convert property value of type [java.lang.String] to required type [java.sql.Date]

I looked up the CustomDateEditor and found this in the Spring docs on CustomDateEditor: it is a "PropertyEditor for java.util.Date".

Thus, my question is this. Does anyone know how to use initBinder on a field of type java.sql.Date?

Jim

Jurijus Jarmakas
Nov 29th, 2004, 11:28 AM
in initBinder register the Date Editor, by default it is "off"

binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("MM/dd/yyyy"), true));

change parameters accordingly...