Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: how to change exception message for date fields?

  1. #1

    Default how to change exception message for date fields?

    hi, i have a date field that requires MM/dd/yyyy input.
    however, if a user types "xyz", the form is re-displayed
    with an error message as follows:

    Failed to convert property value of type [java.lang.String] to required type [java.util.Date] for property 'startDate'; nested exception is java.lang.IllegalArgumentException: Could not parse date: Unparseable date: "xyz"

    Suppose, we dont use any validator (client or server-side), how
    can i change the above to let a user see a friendly message?

    I would like to say that server side validator (specified through
    <property name="validator"><ref bean="beanValidator"/></property>)
    is not working, because a validator is called after
    data binding is finished.

    correct me if i am wrong.

    thanks for your input!

    pete

    p.s. i am using spring 1.1.5 and Commons validator 1.1.4

  2. #2

    Default

    Hi Pete,

    have you already registered a customEditor in your Controllers initBinder() method?

  3. #3

    Default

    yes, i registered a customEditor for date and it is able to
    take input like MM/dd/yyyy. but it throws that horrible
    message to users in chase a user enterd something like
    MM/dd/20005 (5 digits). i am trying to make it robust and
    user friendly.

    thanks, pete

  4. #4

    Default

    does anybody there have knowledge for handling this?

    thanks, pete

  5. #5

    Default

    I'm having the same issue.

    I'm actually attempting to code a solution now. I think I might try and replace the first FieldError in the List of errors with the error I want it to have. I'll post here if I come up with a solution.

  6. #6

    Default

    In my view I use, ${status.errorMessage} to display the error message. It grabs the first error and displays it. The problem we're having is that the Spring-error message is the first on in the list, so it is displayed.

    I tried to modify the list. (remove the first error, or add my own to the first position) But it looks like I can't modify the list directly. I keep getting errors like this:

    java.lang.UnsupportedOperationException
    java.util.Collections$UnmodifiableList.add(Collect ions.java:1144)

    We must be missing something. It can't be this difficult.

  7. #7

    Default

    michael,

    i made a similar attempt at the server side trying to
    replace the error message, but i found the message is
    not replaceable. sounds similar to you?

    thanks, pete

  8. #8

    Default

    Yep. No luck.

    I'm at a lose for this. I wouldn't think I'd have to write a lot of code to get this to work. Can any of the spring guys shed some light on a method to solve this?

  9. #9

    Default

    can any spring pro out there helping us out on this?

    thanks, pete

  10. #10
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    Sorry for the delay...

    I haven't got the time to fully read the thread, but I think you're looking for the default error messages? The DataBinder adds a couple of pre-defined keys if the field is required, or if a type mismatch occurred. Have a look at the following classes to see what those defaults are. The DefaultMessageCodesResolver tries a couple of codes before falling back to the default (which is what you're getting).

    If you define one of the codes (mentioned in DefaultMessageCodesResolver) in your message bundle (registered as the MessageSource in your context) you should be fine.

    Hope this helps,

    regards,
    Alef Arendsen



    http://www.springframework.org/docs/...sResolver.html
    http://www.springframework.org/docs/...ataBinder.html
    Alef Arendsen
    SpringSource
    http://www.springsource.com

Similar Threads

  1. Message Bundle - No Message Found exception
    By arumugamkasi in forum Web
    Replies: 18
    Last Post: Jun 20th, 2011, 04:24 AM
  2. Context initialization failed
    By kanonmicke in forum Container
    Replies: 7
    Last Post: Sep 29th, 2005, 12:35 AM
  3. UpgradeAcegi Security System from 0.6.1 to 0.8.3
    By mannobug in forum Security
    Replies: 3
    Last Post: Sep 23rd, 2005, 07:00 PM
  4. Replies: 0
    Last Post: Jul 11th, 2005, 05:49 PM
  5. Replies: 3
    Last Post: Nov 8th, 2004, 07:30 PM

Posting Permissions

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