bruno 2003/06/30 07:16:02
Modified: src/blocks/woody/java/org/apache/cocoon/woody/formmodel AggregateField.java Log: Fixed getValue() method Revision Changes Path 1.3 +22 -5 cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/AggregateField.java Index: AggregateField.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/AggregateField.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- AggregateField.java 27 Jun 2003 13:01:46 -0000 1.2 +++ AggregateField.java 30 Jun 2003 14:16:02 -0000 1.3 @@ -88,7 +88,6 @@ private String enteredValue; private List fields = new ArrayList(); private Map fieldsById = new HashMap(); - private boolean satisfiesSplitExpr = false; private ValidationError validationError; protected AggregateField(AggregateFieldDefinition definition) { @@ -106,7 +105,6 @@ public void readFromRequest(FormContext formContext) { enteredValue = formContext.getRequest().getParameter(getFullyQualifiedId()); - satisfiesSplitExpr = false; validationError = null; // whitespace & empty field handling @@ -133,7 +131,13 @@ // objects) ((Field)fieldsById.get(splitMapping.getFieldId())).setValue(result); } - satisfiesSplitExpr = true; + } else { + // set values of the fields to null + Iterator fieldsIt = fields.iterator(); + while (fieldsIt.hasNext()) { + Field field = (Field)fieldsIt.next(); + field.setValue(null); + } } } } @@ -142,7 +146,7 @@ * Always returns a String for this widget (or null). */ public Object getValue() { - if (satisfiesSplitExpr) { + if (fieldsHaveValues()) { String value; try { value = (String)definition.getCombineExpression().evaluate(new ExpressionContextImpl(this, true)); @@ -157,6 +161,19 @@ } } + /** + * Returns true if their is at least one field which has a value. + */ + private boolean fieldsHaveValues() { + Iterator fieldsIt = fields.iterator(); + while (fieldsIt.hasNext()) { + Field field = (Field)fieldsIt.next(); + if (field.getValue() != null) + return true; + } + return false; + } + public boolean validate(FormContext formContext) { // valid unless proven otherwise validationError = null; @@ -166,7 +183,7 @@ return false; } else if (enteredValue == null) return true; - else if (!satisfiesSplitExpr) { + else if (!fieldsHaveValues()) { Object splitFailMessage = definition.getSplitFailMessage(); if (splitFailMessage != null) validationError = new ValidationError(splitFailMessage);