5 Replies Latest reply on Aug 2, 2006 12:42 PM by gavin.king

    Partial validation

    guilhermesilveira

      I would like to know if there is any way to partially validate an object.

      For example, there is an update form responsible for updating just 3 out of 10 form fields... for now I have implemented this using Validator by my own. Something like:

      @IfInvalid(fields="myobj.field1, myobj.field2, myobj.field3", ...)

      There is also a problem that Hibernate validator does not give a method capable of validating a single field either recursively or not so I implemented the following algo:

      - split the field name ("myobj.field1")
      - grab the field value for each but the last string
      - for the last string: if the field has an @Valid, call hibernate validator validate method for the entire object pointed by this field, if it doesnt, its a simple property so call hibernate validator validate method on the previous class type and object using this specific field

      I want to know if there was something already done in this way or if I should have created a simple class to model this form although I really wouldnt like to do so..

      Guilherme Silveira

        • 1. Re: Partial validation
          pmuir

          You could try using the <s:validate> ui component; it will validate just the field it is attached to using the hibernate validator. I've found it a much more flexible/robust approach (but it does require you to add the tag to each input - potentially a big job!)

          • 2. Re: Partial validation
            gavin.king

            Actually, if you use <s:validateAll>, you don't need a tag on each input, just one that surrounds all the inputs you want to validate.

            by the way, I am migrating the Seam examples away from @IfInvalid. It was a nice experiment, but experience has show it is not the best approach.

            • 3. Re: Partial validation
              guilhermesilveira

              Are the new examples only on the repository on already in the latest release?

              Guilherme

              • 4. Re: Partial validation
                zeddmaxim

                 

                "gavin.king@jboss.com" wrote:
                Actually, if you use <s:validateAll>, you don't need a tag on each input, just one that surrounds all the inputs you want to validate.

                by the way, I am migrating the Seam examples away from @IfInvalid. It was a nice experiment, but experience has show it is not the best approach.


                If @IfInvalid is no longer the best approach, what is now the recommended approach? Pointers to any other posts or docs would be appreciated on this subject.

                • 5. Re: Partial validation
                  gavin.king

                  <s:validate> / <s:validateAll>, as per the examples in the current Seam release.