cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sylv...@apache.org
Subject svn commit: r158102 - cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/Form.js cocoon/branches/BRANCH_2_1_X/status.xml
Date Fri, 18 Mar 2005 17:04:40 GMT
Author: sylvain
Date: Fri Mar 18 09:04:39 2005
New Revision: 158102

URL: http://svn.apache.org/viewcvs?view=rev&rev=158102
Log:
Add cleanup and restore hook on Form.showForm. This replaces and enhances the "fun" parameter
that was added recently but which is clearly not sufficient because a form is often displayed
more than once.
I know we're in code freeze, but the previous contract (added after 2.1.6) was buggy.

Modified:
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/Form.js
    cocoon/branches/BRANCH_2_1_X/status.xml

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/Form.js
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/Form.js?view=diff&r1=158101&r2=158102
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/Form.js
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/Form.js
Fri Mar 18 09:04:39 2005
@@ -85,27 +85,38 @@
 }
 
 /**
+ * Set a function that will be called when 
+ */
+
+/**
  * Manages the display of a form and its validation.
  *
- * This uses some additionnal propertied on the form object :
+ * This uses some additionnal properties on the form object :
  * - "locale" : the form locale (default locale is used if not set)
+ * - "cleanupHook": a function called after having sent the page displaying the form. This
is equivalent
+ *       to the "fun" argument of sendPageAndWait(), which allows to perform some cleanup
when the pipeline
+ *       has been processed. The function is called with a single parameter which is the
form it is attached to.
+ * - "restoreHook": a function called before processing the form when it has been submitted
by
+ *       the browser. This allows to restore some environment that is needed by the form
processing.
+ *       The function is called with a single parameter which is the form it is attached
to.
  *
  * On return, the calling code can check some properties to know the form result :
  * - "isValid" : true if the form was sucessfully validated
  * - "submitId" : the id of the widget that triggered the form submit (can be null)
  *
  * @parameter uri the page uri (like in cocoon.sendPageAndWait())
- * @parameter bizdata some business data for the view (like in cocoon.sendPageAndWait()).
+ * @parameter viewdata some data for the view (like in cocoon.sendPageAndWait()).
  *            The "{FormsPipelineConfig.CFORMSKEY}" and "locale" properties are added to
this object.
+ * @parameter ttl the time to live of the continuation used to display the form
  */
-Form.prototype.showForm = function(uri, bizData, fun, ttl) {
+Form.prototype.showForm = function(uri, viewdata, ttl) {
 
-    if (bizData == undefined) bizData = new Object();
-    bizData[Packages.org.apache.cocoon.forms.transformation.FormsPipelineConfig.CFORMSKEY]
= this.form;
+    if (viewdata == undefined) viewdata = new Object();
+    viewdata[Packages.org.apache.cocoon.forms.transformation.FormsPipelineConfig.CFORMSKEY]
= this.form;
 
     if (this.locale == null)
         this.locale = java.util.Locale.getDefault();
-    bizData["locale"] = this.locale;
+    viewdata["locale"] = this.locale;
 
     // Keep the first continuation that will be created as the result of this function
     var result = null;
@@ -118,13 +129,17 @@
 
     if (comingBack) {
         // We come back to the bookmark: process the form
+        
+	    if (this.restoreHook) {
+	        this.restoreHook(this);
+	    }
         var formContext = new Packages.org.apache.cocoon.forms.FormContext(cocoon.request,
this.locale);
 
-        // Prematurely add the bizData as in the object model so that event listeners can
use it 	 
+        // Prematurely add the viewdata as in the object model so that event listeners can
use it 	 
         // (the same is done by cocoon.sendPage()) 	 
         // FIXME : hack needed because FOM doesn't provide access to the object model 	 
         var objectModel = org.apache.cocoon.components.ContextHelper.getObjectModel(this.avalonContext);
	 
-        org.apache.cocoon.components.flow.FlowHelper.setContextObject(objectModel, bizData);
	 
+        org.apache.cocoon.components.flow.FlowHelper.setContextObject(objectModel, viewdata);
	 
 
         finished = this.form.process(formContext);
         if (finished) {
@@ -136,10 +151,13 @@
         }
     }
     comingBack = true;
-    cocoon.sendPage(uri, bizData, bookmark);
-    if (fun && fun instanceof Function) {
-        fun();
+    cocoon.sendPage(uri, viewdata, bookmark);
+    
+    // Clean up after sending the page
+    if (this.cleanupHook) {
+        this.cleanupHook(this);
     }
+    
     FOM_Cocoon.suicide();
 }
 

Modified: cocoon/branches/BRANCH_2_1_X/status.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/status.xml?view=diff&r1=158101&r2=158102
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml Fri Mar 18 09:04:39 2005
@@ -322,14 +322,17 @@
      <br/>
      Form.js :
      <ul>
-       <li>added "fun" and "ttl" parameters to <code>Form.showForm()</code>,
which now has the exact
-           same parameters as cocoon.sendPageAndWait().</li>
        <li>the argument of <code>new Form(...)</code> can now be either
a String or a DOM Element.
            Accepting an Element allows the use of any kind of dynamic process to build the
form
            definition.</li>
        <li><code>Form.showForm()</code> now uses a single continuation,
which saves memory and speeds
            up processing by shortening the continuation chain when the user has a long interaction
            with the form.</li>
+       <li>"ttl" parameter added to <code>Form.showForm()</code>, which
has the same meaning as for cocoon.sendPageAndWait().</li>
+       <li>new "cleanupHook" property on Form: this is a function that is called each
time the form is displayed.
+           This is similar to the "fun" parameter of cocoon.sendPageAndWait().</li>
+       <li>new "restoreHook" property on Form: this is a function that is called each
time the continuation is called back,
+           to restore if needed the execution environment before processing the request.</li>
      </ul>
      <br/>
      Actions:



Mime
View raw message