Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 30808 invoked from network); 6 Nov 2003 21:33:30 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 6 Nov 2003 21:33:30 -0000 Received: (qmail 37075 invoked by uid 500); 6 Nov 2003 21:33:18 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 36917 invoked by uid 500); 6 Nov 2003 21:33:17 -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 36906 invoked by uid 500); 6 Nov 2003 21:33:17 -0000 Delivered-To: apmail-cocoon-2.1-cvs@apache.org Received: (qmail 36903 invoked from network); 6 Nov 2003 21:33:17 -0000 Received: from unknown (HELO minotaur.apache.org) (209.237.227.194) by daedalus.apache.org with SMTP; 6 Nov 2003 21:33:17 -0000 Received: (qmail 30788 invoked by uid 1342); 6 Nov 2003 21:33:28 -0000 Date: 6 Nov 2003 21:33:28 -0000 Message-ID: <20031106213328.30787.qmail@minotaur.apache.org> From: vgritsenko@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 vgritsenko 2003/11/06 13:33:28 Modified: src/blocks/woody/java/org/apache/cocoon/woody/formmodel Field.java Log: Do not try to convertToString() null values; removes bunch of exceptions from the log. Revision Changes Path 1.16 +22 -15 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.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- Field.java 3 Nov 2003 23:16:12 -0000 1.15 +++ Field.java 6 Nov 2003 21:33:28 -0000 1.16 @@ -92,6 +92,7 @@ private ValidationError validationError; + public Field(FieldDefinition fieldDefinition) { this.definition = fieldDefinition; } @@ -107,18 +108,18 @@ public Object getValue() { // Parse the value if (this.needsParse) { - + // Clear value, it will be recomputed this.value = null; if (this.enteredValue == null) { this.value = null; this.needsParse = false; this.needsValidate = true; - + } else { // Parse the value this.value = definition.getDatatype().convertFromString(this.enteredValue, getForm().getLocale()); - + if (this.value == null) { // Conversion failed this.validationError = new ValidationError( @@ -126,7 +127,7 @@ new String[] {"datatype." + definition.getDatatype().getDescriptiveName()}, new boolean[] { true } ); - + // No need for further validation (and need to keep the above error) this.needsValidate = false; } else { @@ -139,8 +140,9 @@ // 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) + if (isValidating) { return value; + } // Validate the value if (this.needsValidate) { @@ -164,32 +166,37 @@ isValidating = false; } } - + return this.validationError == null ? this.value : null; } public void setValue(Object newValue) { - if (newValue != null && !definition.getDatatype().getTypeClass().isAssignableFrom(newValue.getClass())) + if (newValue != null && !definition.getDatatype().getTypeClass().isAssignableFrom(newValue.getClass())) { throw new RuntimeException("Incorrect value type for \"" + getFullyQualifiedId() + - "\" (expected " + definition.getDatatype().getTypeClass() + ", got " + newValue.getClass() + "."); + "\" (expected " + definition.getDatatype().getTypeClass() + + ", got " + newValue.getClass() + "."); + } Object oldValue = this.value; - + boolean changed = ! (oldValue == null ? "" : oldValue).equals(newValue == null ? "" : newValue); - + // Do something only if value is different or null // (null allows to reset validation error) if (changed || newValue == null) { - this.value = newValue; - + this.needsParse = false; this.validationError = null; // Force validation, even if set by the application this.needsValidate = true; - this.enteredValue = definition.getDatatype().convertToString(newValue, getForm().getLocale()); - + if (newValue == null) { + this.enteredValue = null; + } else { + this.enteredValue = definition.getDatatype().convertToString(newValue, getForm().getLocale()); + } + if (changed) { getForm().addWidgetEvent(new ValueChangedEvent(this, oldValue, newValue)); }