Results 1 to 3 of 3

Thread: Commons validation.xml only works for depends="required"

  1. #1
    Join Date
    Jul 2009
    Posts
    12

    Default Commons validation.xml only works for depends="required"

    Hello

    I am using spring 2.5.6 and am attempting to integrate commons validator so that I can have declaritive validation using validation.xml, validator-rules.xml

    I have followed the instructions at the following

    https://springmodules.dev.java.net/d...alidation.html

    and have validator-rules.xml and validation.xml in place.

    The problem is that the only validator that seems to trigger is depends="required". None of the others do. For example if I have depends="float" or depends="date" the validators just seem to get bypassed and the erroneous input results in java errors.

    Ive searched the forums extensively but cannot find a solution. Can anybody give me some pointers?

    Thanks

  2. #2
    Join Date
    Jul 2009
    Posts
    12

    Default

    In further experimentation I have noticed the following. All of the validators work fine provided the field of the underlying bean is a string. It appears as though the spring modules is doing things in the wrong order, i.e. it appears to be doing
    1) attempt to populate the bean with submitted data
    2) validate the submitted data

    A more logical order would be
    1) validate the submitted data
    2) attempt to populate bean with submitted data

    Has anyone else come across this strange behaviour?

  3. #3
    Join Date
    Jul 2009
    Posts
    12

    Default

    Ive made the discovery that commons validation is not required to check that e.g. a value is a float or a date. Instead you rely on spring binding errors and have a message in messages.properties.

    e.g. to handle all invalid dates:

    typeMismatch.java.util.Date={0} is an invalid date. Use format DD/MM/YYYY.

    However the only issue with this is that {0} will get populated with the field name, e.g. retirementDate:

    retirementDate is an invalid date. Use format DD/MM/YYYY.

    If you wanted something more user friendly you would need

    typeMismatch.retirementDate=Retirement Date is an invalid date. Use format DD/MM/YYYY.

Posting Permissions

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