cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From giac...@apache.org
Subject svn commit: r158108 - cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/binding/MultiValueJXPathBinding.java
Date Fri, 18 Mar 2005 17:16:28 GMT
Author: giacomo
Date: Fri Mar 18 09:16:24 2005
New Revision: 158108

URL: http://svn.apache.org/viewcvs?view=rev&rev=158108
Log:
enable multi-value fields to bind in both directions

Modified:
    cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/binding/MultiValueJXPathBinding.java

Modified: cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/binding/MultiValueJXPathBinding.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/binding/MultiValueJXPathBinding.java?view=diff&r1=158107&r2=158108
==============================================================================
--- cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/binding/MultiValueJXPathBinding.java
(original)
+++ cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/binding/MultiValueJXPathBinding.java
Fri Mar 18 09:16:24 2005
@@ -15,6 +15,7 @@
  */
 package org.apache.cocoon.forms.binding;
 
+import java.util.Collection;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.Locale;
@@ -23,6 +24,7 @@
 import org.apache.cocoon.forms.datatype.convertor.Convertor;
 import org.apache.cocoon.forms.datatype.convertor.ConversionResult;
 import org.apache.cocoon.forms.formmodel.Widget;
+import org.apache.commons.jxpath.AbstractFactory;
 import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.Pointer;
 
@@ -102,6 +104,21 @@
         Object[] values = (Object[])widget.getValue();
 
         JXPathContext multiValueContext = jctx.getRelativeContext(jctx.createPath(this.multiValuePath));
+        multiValueContext.setFactory( new AbstractFactory() {
+            public boolean createObject(JXPathContext context, Pointer pointer,
+                                        Object parent, String name, int index) {
+                final Object o = context.getValue(name);
+                if( Collection.class.isAssignableFrom( o.getClass() ) ) {
+                    ((Collection)context.getValue(name)).add(null);
+                } else if( o.getClass().isArray() ) {
+                    // not yet supported
+                    return false;
+                } else {
+                    return false;
+                }
+                return true;
+            }
+        });
         // Delete all that is already present
         multiValueContext.removeAll(this.rowPath);
 



Mime
View raw message