cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel Field.java
Date Wed, 08 Oct 2003 10:03:19 GMT
bruno       2003/10/08 03:03:19

  Modified:    src/blocks/woody/java/org/apache/cocoon/woody/formmodel
                        Field.java
  Log:
  Fixed problem with endless loop while validating reported by Antonio
  
  Revision  Changes    Path
  1.12      +26 -16    cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/Field.java
  
  Index: Field.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/Field.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Field.java	25 Sep 2003 17:37:30 -0000	1.11
  +++ Field.java	8 Oct 2003 10:03:19 -0000	1.12
  @@ -88,7 +88,8 @@
       // but need to validate (error if field is required)
       private boolean needsParse = true;
       private boolean needsValidate = true;
  -    
  +    private boolean isValidating = false;
  +
       private ValidationError validationError;
   
       public Field(FieldDefinition fieldDefinition) {
  @@ -135,24 +136,33 @@
                   }
               }
           }
  -        
  +
  +        // if getValue() is called on this field while we're validating, then it's because
a validation
  +        // rule called getValue(), so then we just return the parsed (but not validated)
value to avoid an endless loop
  +        if (isValidating)
  +            return value;
  +
           // Validate the value
           if (this.needsValidate) {
  -            
  -            // Clear error, it will be recomputed
  -            this.validationError = null;
  -            
  -            if (this.value == null) {
  -                // No value : is it required ?
  -                if (this.definition.isRequired()) {                    
  -                    this.validationError = new ValidationError("general.field-required");
  +            isValidating = true;
  +            try {
  +                // Clear error, it will be recomputed
  +                this.validationError = null;
  +
  +                if (this.value == null) {
  +                    // No value : is it required ?
  +                    if (this.definition.isRequired()) {
  +                        this.validationError = new ValidationError("general.field-required");
  +                    }
  +
  +                } else {
  +                    this.validationError = definition.getDatatype().validate(value, new
ExpressionContextImpl(this));
                   }
  -                
  -            } else {
  -                this.validationError = definition.getDatatype().validate(value, new ExpressionContextImpl(this));
  +
  +                this.needsValidate = false;
  +            } finally {
  +                isValidating = false;
               }
  -            
  -            this.needsValidate = false;
           }
           
           return this.validationError == null ? this.value : null;
  
  
  

Mime
View raw message