Results 1 to 2 of 2

Thread: re: date validation

  1. #1
    Join Date
    Sep 2008
    Posts
    8

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

    Default

    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.

Tags for this Thread

Posting Permissions

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