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));
}