Announcement Announcement Module
Collapse
No announcement yet.
Cannot bind java.sql.date in CustomDateEditor Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cannot bind java.sql.date in CustomDateEditor

    I would like to bind a date field which is in the format of 2005-07-04 to the java.sql.Date format, so I register using these

    Code:
    	protected void initBinder(HttpServletRequest req, ServletRequestDataBinder binder) throws Exception{
    		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
    		dateFormat.setLenient(false);
    		binder.registerCustomEditor(java.sql.Date.class, new CustomDateEditor(dateFormat, true));
    	}
    But in gives me exception on:
    Code:
    Failed to convert property value of type [java.lang.String] to required type [java.sql.Date] for property 'inputDate'
    If I change that inputDate command field to the type of java.util.Date, everything works fine.

    Anyway to make the CustomDateEditor be able process java.sql.Date directly? Or else I need to do the casting myself.

  • #2
    Use add this line:
    Code:
    binder.registerCustomEditor(java.sql.Date.class, new CustomDateEditor(dateFormat, true));
    But I recommend you to not to use java.sql.date. I had many problems with it and now I am using only java.util.date

    Comment


    • #3
      Sorry, I have post the wrong code, and now fixed the 1st post.
      I'm already using java.sql.Date in the registerCustomEditor method.

      Comment

      Working...
      X