Results 1 to 3 of 3

Thread: Trapping bind errors to display as failed validation error

  1. #1
    Join Date
    Apr 2005
    Posts
    19

    Default Trapping bind errors to display as failed validation error

    Hi,

    I've successfully created validators to validate form input but I have one small issue: When a field that maps to a numeric field on command object is left blank or alfa data is entered, the following error is displayed:

    Code:
    Failed to convert property value of type [java.lang.String] to required type [java.lang.Integer] for property 'version'; nested exception is java.lang.NumberFormatException ...
    Where do I trap this exception and

    a) ignore it if the field is optional
    b) display a more user friendly message.

    Thanks very much. Regards,
    Stefan

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    You need to add something like:
    Code:
    binder.registerCustomEditor(Integer.class, "myNumericProperty", new CustomNumberEditor(Integer.class, true));
    The true is to allow empty entries.

    NB. You'll still get validation error messages if you enter alpha characters - this is correct behaviour.

  3. #3
    Join Date
    Apr 2005
    Posts
    19

    Default

    Thanks Katentim,

    I've just checked the docs and both the built-in CustomNumberEditor and CustomDateEditor have a parameter to allow empty fields! Lovely

    Regards,
    Stefan

Similar Threads

  1. ERROR: Context initialization failed
    By makhlo in forum Architecture
    Replies: 8
    Last Post: Jul 11th, 2008, 01:41 AM
  2. Replies: 2
    Last Post: Apr 28th, 2005, 02:01 PM
  3. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  4. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 PM
  5. Replies: 4
    Last Post: Nov 5th, 2004, 03:59 AM

Posting Permissions

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