3 Replies Latest reply on Dec 13, 2005 7:20 PM by patrick_ibg

    RFC: Validation groups

    rdewell

      I find that if a view contains very granular forms, then it is sometimes convenient for the same backing bean to handle several of these forms. In other words: a different action per form, where each action is on the same backing bean.

      This doesn't work well for server side Seam validation, though, because the validation on a single backing bean is not as granular as JSF forms. Essentially, all actions on the same bean marked @IfInvalid will do the exact same validation, letting Seam ultimately support just one form per backing bean.

      A solution that allows Seam to handle multiple form validation in the same backing bean might be a notion of "validation groups":

      - A new validation related annotation like @ValidGroup(name="ProductUpdateFields") that is coupled with each validated field/method such as @NotNull @ValidGroup(...).

      - A new annotation called @IfGroupsInvalid that contains a list of the grouped validators to include in the validation process. For example: @ IfGroupsInvalid(groups={'ProductUpdateFields'}). You'd also need an optional parameter on this annotation like "includeDefault=false", so that you can tell it to include ungrouped validations. In short, @IfGroupsInvalid(includeDefault=true, groups={}) would be semantically equivalent to the current @IfInvalid.

      Then, only the validated fields/methods that are coupled with @ValidGroup(name="ProductUpdateFields") will get validated when coupled with @IfGroupsInvalid instead of @IfInvalid.

      I'm not sure if anyone else is running into this, but I personally would find it pretty handy. Of course there are ways around this using more granular beans, one bean per form in other words, but that's not very convenient in some situations, imo.

      Ryan

        • 1. Re: RFC: Validation groups
          gavin.king

          I'm inclined to think that a better approach in this case would be to call Hibernate Validator programmatically, rather than via annotations. But I might be wrong. I think I kinda see what you are doing. I'd like to know if this is something that other people run into.

          • 2. Re: RFC: Validation groups
            patrick_ibg

            I have some wizards which basically null out the appropriate form beans and put them back in when it's on the right screen.

            This doesn't solve your problem though, as you have no idea in advance which form will get submitted.

            Maybe as an alternative, create a @ValidateFor (names = {"seamName1", "name2"}) annotation which can decorate either a method or a class.

            • 3. Re: RFC: Validation groups
              patrick_ibg

              This could also fold in the @IfInvalid annotation:

              @ValidateFor (names = {"seamName1", "name2"}, invalidOutcome = REDISPLAY)