Results 1 to 2 of 2

Thread: CustomEditor for java.sql.Date ?

  1. #1
    Join Date
    Nov 2004
    Posts
    6

    Default CustomEditor for java.sql.Date ?

    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

  2. #2
    Join Date
    Nov 2004
    Location
    IL, USA
    Posts
    61

    Default

    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...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •