Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 44511 invoked from network); 8 Oct 2003 10:03:21 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 8 Oct 2003 10:03:21 -0000 Received: (qmail 74897 invoked by uid 500); 8 Oct 2003 10:03:03 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 74730 invoked by uid 500); 8 Oct 2003 10:03:02 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 74718 invoked by uid 500); 8 Oct 2003 10:03:02 -0000 Delivered-To: apmail-cocoon-2.1-cvs@apache.org Received: (qmail 74715 invoked from network); 8 Oct 2003 10:03:02 -0000 Received: from unknown (HELO minotaur.apache.org) (209.237.227.194) by daedalus.apache.org with SMTP; 8 Oct 2003 10:03:02 -0000 Received: (qmail 44484 invoked by uid 1638); 8 Oct 2003 10:03:19 -0000 Date: 8 Oct 2003 10:03:19 -0000 Message-ID: <20031008100319.44483.qmail@minotaur.apache.org> From: bruno@apache.org To: cocoon-2.1-cvs@apache.org Subject: cvs commit: cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel Field.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N 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;