Announcement Announcement Module
Collapse

Spring Modules forum decommissioned in favor of Spring Extensions

As the Spring Modules project has been replaced by the Spring Extensions (http://www.springsource.org/extensions) project, this forum has been decommissioned in favour of Spring Extensions one at:
http://forum.springsource.org/forumdisplay.php?f=44

Please see the Spring Extensions home page for a complete list of current projects in Java, .NET and ActionScript. You can also propose one if you want.

Cheers,
Costin Leau
SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
http://twitter.com/costinl
See more
See less
Commons validation.xml only works for depends="required" Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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?

    Comment


    • #3
      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.

      Comment

      Working...
      X