0 Replies Latest reply on Nov 21, 2008 9:46 PM by Laurent Morissette

    date Range vialidation

    Laurent Morissette Newbie

      Hello fellow Seamers :)

      I need to validate that a certain date type field is within secified range.

      I made a custom Validator-based annotation but I can't seem to make it work correctly so any advices would be greatly appreciated.

      FYI here are my validator Elements (code):

      My annotation:

      import static java.lang.annotation.ElementType.FIELD;
      import static java.lang.annotation.ElementType.METHOD;
      import static java.lang.annotation.RetentionPolicy.RUNTIME;
      import java.lang.annotation.Documented;
      import java.lang.annotation.Retention;
      import java.lang.annotation.Target;
      import org.hibernate.validator.ValidatorClass;
      @Target({ METHOD, FIELD})
      public @interface DateRange {
       String after() default "";
       String before() default "";
       String message() default ("validator.daterange");

      The Validator itself

      import java.io.Serializable;
      import java.util.Date;
      import org.hibernate.validator.Validator;
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      public class DateRangeValidator implements Validator<DateRange>, Serializable  {
           private static final long serialVersionUID = 7958814426292792622L;
           private long after=0l;
           private long before=0l;
           public void initialize(DateRange parameters) {
                after=new Long(parameters.after()).longValue();
                before=new Long(parameters.before()).longValue();
           public boolean isValid(Object value ) {
                 long lValue=((Date)value).getTime();
                 if(lValue<after) return false;
                 if(lValue>before) return false;
                 if((lValue>=after) &&(lValue<=before))return true;
                return false;

      actually, the validator is never called

      Thanks in advance for your help!