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

    RFC: Validation groups

    ryan dewell Novice

      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