0 Replies Latest reply on Jan 13, 2009 1:50 PM by Lydia Ares

    annotation "@Valid" necessary?

    Lydia Ares Newbie

      Hi,
      just wondering what's the correct way to code my domain class (entity).
      I have a list-type property and the list elements' classes are an inner class of my entity. Like this:


      @Entity
      public class AuthMethodGroup {
      
              @Id
              private String id;
              
              @Valid
              private List<AuthNMethod> authNMethods;
              
              /** Constructor */
              public AuthMethodGroup() {
                      authNMethods = new ArrayList<AuthNMethod>();
                      authNMethods.add(new AuthNMethod());
                      authNMethods.add(new AuthNMethod());
              }
              
              public AuthNMethod getFirstAuthNMethod() {
                      return authNMethods.get(0);
              }
              
              public AuthNMethod getSecondAuthNMethod() {
                      return authNMethods.get(1);
              }
              
              public static class AuthNMethod {
      
                      private String name;
                      
                      @Min(value=0, message="#{messages['validation.min0']}")
                      private int level;
                      
                      // ------- getters/setters-------
              }
      
              // ------- more getters/setters-------
      }
      



      I expose the level property of AuthNMethod in my page and I want to have it validated (should not be negative) with s:validateAll:



      <h:form>
        <s:validateAll>
          <h:inputText value="#{authMethodGroup.firstAuthNMethod.level}" required="true" />
        </s:validateAll>
      </h:form>
      



      Validation works fine.


      The thing is that I noticed that it even works without the @Valid annotation on the property authNMethods!


      So can I safely drop the annotation?