cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sylv...@apache.org
Subject svn commit: r349806 - in /cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/binding: RepeaterJXPathBinding.java RepeaterJXPathBindingBuilder.java
Date Tue, 29 Nov 2005 20:45:54 GMT
Author: sylvain
Date: Tue Nov 29 12:45:45 2005
New Revision: 349806

URL: http://svn.apache.org/viewcvs?rev=349806&view=rev
Log:
Start merging fb:simple-repeater behaviour in fb:repeater

Modified:
    cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/binding/RepeaterJXPathBinding.java
    cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/binding/RepeaterJXPathBindingBuilder.java

Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/binding/RepeaterJXPathBinding.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/binding/RepeaterJXPathBinding.java?rev=349806&r1=349805&r2=349806&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/binding/RepeaterJXPathBinding.java
(original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/binding/RepeaterJXPathBinding.java
Tue Nov 29 12:45:45 2005
@@ -117,29 +117,34 @@
                     + "] referenced in the binding does not exist in the form definition.");
         }
         repeater.clear();
-        int initialSize = repeater.getSize();
-        
-        // build a jxpath iterator for pointers
-        JXPathContext repeaterContext =
-            jxpc.getRelativeContext(jxpc.getPointer(this.repeaterPath));
-        Iterator rowPointers = repeaterContext.iteratePointers(this.rowPath);
-        //iterate through it
-        while (rowPointers.hasNext()) {
-            // create a new row, take that as the frmModelSubContext
-            Repeater.RepeaterRow thisRow;
-            if (initialSize > 0) {
-                thisRow = repeater.getRow(--initialSize);
-            } else {
-                thisRow = repeater.addRow();
-            }
-            // make a jxpath ObjectModelSubcontext on the iterated element
-            Pointer jxp = (Pointer)rowPointers.next();
-            JXPathContext rowContext = repeaterContext.getRelativeContext(jxp);
-            // hand it over to children
-            if (this.identityBinding != null) {
-                this.identityBinding.loadFormFromModel(thisRow, rowContext);
+
+        Pointer ptr = jxpc.getPointer(this.repeaterPath);
+        if (ptr.getNode() != null) {
+            // There are some nodes to load from
+
+            int initialSize = repeater.getSize();
+
+            // build a jxpath iterator for pointers
+            JXPathContext repeaterContext = jxpc.getRelativeContext(ptr);
+            Iterator rowPointers = repeaterContext.iteratePointers(this.rowPath);
+            //iterate through it
+            while (rowPointers.hasNext()) {
+                // create a new row, take that as the frmModelSubContext
+                Repeater.RepeaterRow thisRow;
+                if (initialSize > 0) {
+                    thisRow = repeater.getRow(--initialSize);
+                } else {
+                    thisRow = repeater.addRow();
+                }
+                // make a jxpath ObjectModelSubcontext on the iterated element
+                Pointer jxp = (Pointer)rowPointers.next();
+                JXPathContext rowContext = repeaterContext.getRelativeContext(jxp);
+                // hand it over to children
+                if (this.identityBinding != null) {
+                    this.identityBinding.loadFormFromModel(thisRow, rowContext);
+                }
+                this.rowBinding.loadFormFromModel(thisRow, rowContext);
             }
-            this.rowBinding.loadFormFromModel(thisRow, rowContext);
         }
         if (getLogger().isDebugEnabled())
             getLogger().debug("done loading rows " + toString());
@@ -154,9 +159,9 @@
     throws BindingException {
         // Find the repeater
         Repeater repeater = (Repeater) selectWidget(frmModel, this.repeaterId);
-        // and his context
+        // and his context, creating the path if needed
         JXPathContext repeaterContext =
-            jxpc.getRelativeContext(jxpc.getPointer(this.repeaterPath));
+            jxpc.getRelativeContext(jxpc.createPath(this.repeaterPath));
         
         // create set of updatedRowIds
         Set updatedRows = new HashSet();
@@ -213,19 +218,15 @@
             }
         }
         if (rowsToDelete.size() > 0) {
-            if (this.deleteRowBinding != null) {
-                // run backwards through the list, so that we don't get into
-                // trouble by shifting indexes
-                for (int i = rowsToDelete.size() - 1; i >= 0; i--) {
+            // run backwards through the list, so that we don't get into
+            // trouble by shifting indexes
+            for (int i = rowsToDelete.size() - 1; i >= 0; i--) {
+                if (this.deleteRowBinding != null) {
                     this.deleteRowBinding.saveFormToModel(frmModel,
-                            rowsToDelete.get(i));
-                }
-            } else {
-                if (getLogger().isWarnEnabled()) {
-                    getLogger().warn(
-                            "RepeaterBinding has detected rows to delete, " +
-                            "but misses the <on-delete-row> binding to do it."
-                    );
+                        rowsToDelete.get(i));
+                } else {
+                    // Simply remove the corresponding path
+                    ((JXPathContext)rowsToDelete.get(i)).removePath(".");
                 }
             }
         }
@@ -238,13 +239,14 @@
         }
         // end with rows to insert (to make sure they don't get deleted!)
         if (rowsToInsert.size() > 0) {
-            if (this.insertRowBinding != null) {
                 Iterator rowIterator = rowsToInsert.iterator();
                 //register the factory!
                 while (rowIterator.hasNext()) {
                     Repeater.RepeaterRow thisRow = (Repeater.RepeaterRow)rowIterator.next();
                     // Perform the insert row binding.
-                    this.insertRowBinding.saveFormToModel(repeater, repeaterContext);
+                    if (this.insertRowBinding != null) {
+                        this.insertRowBinding.saveFormToModel(repeater, repeaterContext);
+                    }
                     // -->  create the path to let the context be created
                     Pointer newRowContextPointer = repeaterContext.createPath(
                             this.rowPathForInsert + "[" + indexCount + "]");
@@ -258,12 +260,12 @@
                     getLogger().debug("bound new row");
                     indexCount++;
                 }
-            } else {
-                if (getLogger().isWarnEnabled()) {
-                    getLogger().warn("RepeaterBinding has detected rows to insert, but misses
"
-                            + "the <on-insert-row> binding to do it.");
-                }
-            }
+//            } else {
+//                if (getLogger().isWarnEnabled()) {
+//                    getLogger().warn("RepeaterBinding has detected rows to insert, but
misses "
+//                            + "the <on-insert-row> binding to do it.");
+//                }
+//            }
         }
         if (getLogger().isDebugEnabled()) {
             getLogger().debug("done saving rows " + toString());

Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/binding/RepeaterJXPathBindingBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/binding/RepeaterJXPathBindingBuilder.java?rev=349806&r1=349805&r2=349806&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/binding/RepeaterJXPathBindingBuilder.java
(original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/binding/RepeaterJXPathBindingBuilder.java
Tue Nov 29 12:45:45 2005
@@ -114,9 +114,14 @@
             		existingOnInsert = new JXPathBindingBase[] { otherBinding.getInsertRowBinding()
};
             }
 
+            // Simple mode will be used if no fb:identity, fb:on-bind, fb:on-delete-row,
fb:on-insert-row exists.
+            // in that case, the children of fb:repeater will be used as child bindings
+            boolean simpleMode = true;
             Element childWrapElement =
                 DomHelper.getChildElement(bindingElm, BindingManager.NAMESPACE, "on-bind");
             
+            if (childWrapElement != null) simpleMode = false;
+            
             JXPathBindingBase[] childBindings =
                 assistant.makeChildBindings(childWrapElement,existingOnBind);
             if(childBindings == null)
@@ -124,6 +129,9 @@
 
             Element deleteWrapElement = DomHelper.getChildElement(bindingElm,
                     BindingManager.NAMESPACE, "on-delete-row");
+            
+            if (deleteWrapElement != null) simpleMode = false;
+
             JXPathBindingBase[] deleteBindings = null;
             if (deleteWrapElement != null) {
                 deleteBindings =
@@ -134,6 +142,9 @@
 
             Element insertWrapElement = DomHelper.getChildElement(bindingElm,
                     BindingManager.NAMESPACE, "on-insert-row");
+            
+            if (insertWrapElement != null) simpleMode = false;
+
             JXPathBindingBase insertBinding = null;
             if (insertWrapElement != null) {
                 insertBinding =
@@ -147,6 +158,9 @@
 
             Element identityWrapElement = DomHelper.getChildElement(bindingElm,
                     BindingManager.NAMESPACE, "identity");
+            
+            if (identityWrapElement != null) simpleMode = false;
+
             JXPathBindingBase[] identityBinding = null;
             if (identityWrapElement != null) {
                 // TODO: we can only handle ValueJXPathBinding at the moment:
@@ -166,6 +180,11 @@
                 } else {
                 	identityBinding = existingIdentity;
                 }
+            }
+            
+            if (simpleMode) {
+                // Use the children of the current element
+                childBindings = assistant.makeChildBindings(bindingElm,existingOnBind);
             }
 
             RepeaterJXPathBinding repeaterBinding =



Mime
View raw message