Author: cziegeler
Date: Wed Jan 12 03:25:56 2005
New Revision: 124969

URL: http://svn.apache.org/viewcvs?view=rev&rev=124969
Log:
[PATCH] Allow to use fb:insert-bean with add methods without a parameter 
submitted by  Jens Maukisch <[EMAIL PROTECTED]>  
Modified:
   
cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/InsertBeanJXPathBinding.java
   
cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/InsertBeanJXPathBindingBuilder.java
   cocoon/trunk/src/documentation/xdocs/userdocs/forms/binding.xml

Modified: 
cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/InsertBeanJXPathBinding.java
Url: 
http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/InsertBeanJXPathBinding.java?view=diff&rev=124969&p1=cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/InsertBeanJXPathBinding.java&r1=124968&p2=cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/InsertBeanJXPathBinding.java&r2=124969
==============================================================================
--- 
cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/InsertBeanJXPathBinding.java
     (original)
+++ 
cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/InsertBeanJXPathBinding.java
     Wed Jan 12 03:25:56 2005
@@ -23,8 +23,8 @@
 
 /**
  * InsertBeanJXPathBinding provides an implementation of a [EMAIL PROTECTED] 
Binding}
- * that inserts a new instance of the specified bean (classname) into the 
target
- * back-end model upon save.
+ * that inserts a new instance of the specified bean (classname) or a new 
instance
+ * created by the model itself into the target back-end model upon save.
  * <p>
  * NOTES: <ol>
  * <li>This Binding does not perform any actions when loading.</li>
@@ -58,7 +58,8 @@
      * Registers a JXPath Factory on the JXPath Context.
      * <p>
      * The factory will insert a new instance of the specified bean (classname)
-     * inside this object into the target objectmodel.
+     * inside this object into the target objectmodel or it will just call the
+     * add method if classname is null.
      */
     public void doSave(Widget frmModel, JXPathContext jxpc) throws 
BindingException {
         try {
@@ -67,8 +68,13 @@
             Class[] argTypes = new Class[1];
 
             // instantiate the new object
-            argTypes[0] = Class.forName(this.className);
-            args[0] = argTypes[0].newInstance();
+            if(this.className != null) {
+                   argTypes[0] = Class.forName(this.className);
+                   args[0] = argTypes[0].newInstance();
+            } else {
+               argTypes = null;
+               args = null;
+            }
 
             // lookup the named method on the parent
             Method addMethod =

Modified: 
cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/InsertBeanJXPathBindingBuilder.java
Url: 
http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/InsertBeanJXPathBindingBuilder.java?view=diff&rev=124969&p1=cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/InsertBeanJXPathBindingBuilder.java&r1=124968&p2=cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/InsertBeanJXPathBindingBuilder.java&r2=124969
==============================================================================
--- 
cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/InsertBeanJXPathBindingBuilder.java
      (original)
+++ 
cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/InsertBeanJXPathBindingBuilder.java
      Wed Jan 12 03:25:56 2005
@@ -27,6 +27,10 @@
  * <pre><code>
  * &lt;fb:insert-bean classname="..child-bean-class.." 
addmethod="..method-to-add.."/&gt;
  * </code></pre>
+ * or if the add method creates the new instance itself:
+ * <pre><code>
+ * &lt;fb:insert-bean addmethod="..method-to-add.."/&gt;
+ * </code></pre>
  *
  * @version CVS $Id$
  */
@@ -42,7 +46,7 @@
             CommonAttributes commonAtts = 
JXPathBindingBuilderBase.getCommonAttributes(bindingElm);
 
             String className =
-                DomHelper.getAttribute(bindingElm, "classname");
+                DomHelper.getAttribute(bindingElm, "classname", null);
             String addMethod =
                 DomHelper.getAttribute(bindingElm, "addmethod");
 

Modified: cocoon/trunk/src/documentation/xdocs/userdocs/forms/binding.xml
Url: 
http://svn.apache.org/viewcvs/cocoon/trunk/src/documentation/xdocs/userdocs/forms/binding.xml?view=diff&rev=124969&p1=cocoon/trunk/src/documentation/xdocs/userdocs/forms/binding.xml&r1=124968&p2=cocoon/trunk/src/documentation/xdocs/userdocs/forms/binding.xml&r2=124969
==============================================================================
--- cocoon/trunk/src/documentation/xdocs/userdocs/forms/binding.xml     
(original)
+++ cocoon/trunk/src/documentation/xdocs/userdocs/forms/binding.xml     Wed Jan 
12 03:25:56 2005
@@ -157,7 +157,7 @@
         <tr>
           <td>fb:insert-bean</td>
           <td>inserts an object in a list-type bean property</td>
-          <td>classname, addmethod</td>
+          <td>addmethod, classname (optional)</td>
           <td>none</td>
         </tr>
         <tr>
@@ -495,16 +495,18 @@
       <s2 title="fb:insert-bean">
         <p>Attributes:</p>
         <ul>
-          <li>classname</li>
           <li>addmethod</li>
+          <li>classname (optional)</li>
           <li>direction (optional)</li>
         </ul>
 
         <p>This binding element can only be used when the target object is a 
Javabean.</p>
 
-        <p>It instantiates a new object of the type specified in the classname
-        attribute and calls the method specified in the addmethod attribute on 
the
-        current context object with the newly instantiated object as 
argument.</p>
+        <p>If classname is specified it instantiates a new object of the type 
specified 
+        in the classname attribute and calls the method specified in the 
addmethod 
+        attribute on the current context object with the newly instantiated 
object as argument.
+        If classname is not specified it will just call the addmethod (e.g. if 
the addmethod creates
+        the new instance itself).</p>
 
         <p><strong>NOTE:</strong> This binding is never active in the 'load' 
operation,
         so there is no need to specify the <code>direction="save"</code> to 
protect you model

Reply via email to