You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by sy...@apache.org on 2005/10/20 16:07:27 UTC
svn commit: r326908 -
/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/util/ContainerWidgetAsMap.java
Author: sylvain
Date: Thu Oct 20 07:07:24 2005
New Revision: 326908
URL: http://svn.apache.org/viewcvs?rev=326908&view=rev
Log:
Bug fix in put() when the child widget is a repeater
Modified:
cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/util/ContainerWidgetAsMap.java
Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/util/ContainerWidgetAsMap.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/util/ContainerWidgetAsMap.java?rev=326908&r1=326907&r2=326908&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/util/ContainerWidgetAsMap.java (original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/util/ContainerWidgetAsMap.java Thu Oct 20 07:07:24 2005
@@ -19,6 +19,7 @@
import java.util.AbstractSet;
import java.util.Collection;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -65,15 +66,24 @@
this(container, true);
}
+ /**
+ * Put a value in a child widget. The value must be compatible with the datatype
+ * expected by the child widget. In the case of repeaters and containers, this
+ * datatype is <code>Collection</code> and <code>Map</code> respectively, which
+ * will be used to fill the rows and child widgets.
+ * <p>
+ * Note also that the contract of <code>put</code> requires the previous value
+ * to be returned. In the case of repeaters and containers, the value is a live
+ * wrapper around the actual widget, meaning that it's not different from the
+ * current value.
+ */
public Object put(Object key, Object value) {
String name = (String)key;
if (lowerCase) name = name.toLowerCase();
Widget w = container.getChild(name);
if (w != null) {
- Object result = w.getValue();
- setValue(w, value);
- return result;
+ return setValue(w, value);
} else {
throw new UnsupportedOperationException(container + " has no child named '" + key + "'");
}
@@ -113,22 +123,31 @@
}
}
- private void setValue(Widget w, Object value) {
+ /**
+ * Set a widget's value and returns the previous value as required by put().
+ */
+ private Object setValue(Widget w, Object value) {
if (w instanceof Repeater) {
// Must be a collection
if (!(value instanceof Collection)) {
throw new IllegalArgumentException("A repeater cannot be filled with " + value);
}
- new RepeaterAsList((Repeater)w, lowerCase).addAll((Collection)value);
+ List result = new RepeaterAsList((Repeater)w, lowerCase);
+ result.addAll((Collection)value);
+ return result;
} else if (w instanceof AbstractContainerWidget) {
// Must be a map
if (!(value instanceof Map)) {
throw new IllegalArgumentException("A container cannot be filled with " + value);
}
- new ContainerWidgetAsMap((AbstractContainerWidget)w).putAll((Map)value);
+ Map result = new ContainerWidgetAsMap((AbstractContainerWidget)w);
+ result.putAll((Map)value);
+ return result;
} else {
+ Object result = w.getValue();
w.setValue(value);
+ return result;
}
}