2 Replies Latest reply on Feb 1, 2011 3:22 PM by hmvictor

    JSF and Bean Validation group integration

    nickarls

      Say I have an entity with a @NotNull String name.

       

      I have an inputText value pointing at it and a list of entities to choose from with a commandLink. Since I want the changes to be stashed away in the model when I switch entities, I have immediate=false on the commandLinks.

       

      Now comes the case where I have created a new entity and then choose to navigate away to another entity. When I click the link, of course validation is trigged and failure is ensured.

       

      Are there any good patterns for this? I could of course have different validation groups for the states "new" and "edit". I don't want to write custom constraints for every case just to check the internal state (null @ID = new) etc. But how can I choose which validation group to go by while still maintaining integration with the JSF layer? I could of course bypass the view layer validation altogether and validate manually with different groups in different backing bean actions but binding the messages back to the correct inputText seems a bit cumbersome.

       

      One would think that this kind of scenario would be quite common? Does anyone have any good patterns for this?

       

      Thanks in advance,

         Nik