Announcement Announcement Module
Collapse
No announcement yet.
re: date validation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • re: date validation

    Does anybody know how to get around the following error?

    Can't convert the date to string, because it is not known which parts of the
    date variable are in use. use ?date, ?time or ?datetime built-in, or ?string. or
    ?string (format) built-in with this date.


    I am using jsp for the input field:

    [@form.input path="testDate" /]

    message.properties has this line:

    typeMismatch.java.util.Date={0} is an invalid date.

    Thanks for any tips on trapping the above error!

  • #2
    Sounds like you need to register a CustomDateEditor during the initial binding phase of your form-backing object. If your controllers are annotation-based it would look something like this:

    Code:
    @InitBinder
    protected void initBinder(WebDataBinder binder) {
       SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy");
       binder.registerCustomEditor(Date.class, new CustomDateEditor(format, true));
    }
    Refer to http://static.springsource.org/sprin...alidation.html for clarification on the use of custom property editors.

    http://static.springsource.org/sprin...ateEditor.html should point you in the right direction for CustomDateEditor usage.

    Comment

    Working...
    X