Announcement Announcement Module
No announcement yet.
CustomEditor for java.sql.Date ? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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");
    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?


  • #2
    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...