5 Replies Latest reply on Dec 20, 2006 3:11 AM by Waheed murad

    Problem in writing own annotation in seam

    Waheed murad Newbie

      I want to have my own Hibernate annotaion validator...... named NotEmpty a problem is that when after form submition the only initialize() method is called. isValid() method does not executes......

      below is the code and Thanks in advance for help......


      ------------- Annotation descriptor -------------------
      import java.lang.annotation.Documented;
      import java.lang.annotation.ElementType;
      import java.lang.annotation.Retention;
      import java.lang.annotation.RetentionPolicy;
      import java.lang.annotation.Target;
      import org.hibernate.validator.ValidatorClass;


      @ValidatorClass(value=NotEmptyValidator.class)
      @Target(value={ElementType.METHOD,ElementType.FIELD})
      @Retention(value=RetentionPolicy.RUNTIME)
      @Documented

      public @interface NotEmpty {
      String message() default "Field cannot be empty";
      }

      ------------- Annotation validator -------------------

      import org.hibernate.validator.PropertyConstraint;
      import org.hibernate.validator.Validator;

      import java.io.Serializable;

      public class NotEmptyValidator implements Validator, PropertyConstraint, Serializable {


      public boolean isValid(Object value) {
      System.out.println(" is Valid method called...");
      ..............
      ..............
      return false;
      }

      public void initialize(NotEmpty parameters) {
      System.out.println(" Initialize method called...");
      }

      public void apply(org.hibernate.mapping.Property property){
      System.out.println(" Apply method called...");
      }

      }