cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From coli...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/woody/samples/v2 woody_flow_example.js
Date Mon, 16 Feb 2004 04:54:21 GMT
coliver     2004/02/15 20:54:21

  Modified:    src/blocks/woody/java/org/apache/cocoon/woody/flow/javascript/v2
                        Form.js ScriptableWidget.java
               src/blocks/woody/samples/v2 woody_flow_example.js
  Log:
  Added Form.setBookmark() and cleanup of deleted repeater rows
  
  Revision  Changes    Path
  1.4       +42 -22    cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/flow/javascript/v2/Form.js
  
  Index: Form.js
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/flow/javascript/v2/Form.js,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Form.js	30 Jan 2004 23:53:25 -0000	1.3
  +++ Form.js	16 Feb 2004 04:54:20 -0000	1.4
  @@ -70,9 +70,9 @@
           resolver = cocoon.getComponent(SourceResolver.ROLE);
           src = resolver.resolveURI(uri);
           var form = formMgr.createForm(src);
  -        this.binding = null;
  -        this.formWidget = new Widget(form);
  -        this.local = cocoon.createPageLocal();
  +        this.binding_ = null;
  +        this.formWidget_ = new Widget(form);
  +        this.local_ = cocoon.createPageLocal();
       } finally {
           cocoon.releaseComponent(formMgr);
           if (src != null) resolver.release(src);
  @@ -89,30 +89,54 @@
   Form.prototype.getWidget = function(name) {
       var result;
       if (name == undefined) {
  -        result = this.formWidget;
  +        result = this.formWidget_;
       } else {
  -        result = this.formWidget.getWidget(name);
  +        result = this.formWidget_.getWidget(name);
       }
       return result;
   }
   
   /**
  + * Sets the point in your script that will be returned to when the form is 
  + * redisplayed. If setBookmark() is not called, this is implicitly set to 
  + * the beginning of showForm().
  + */
  +
  +Form.prototype.setBookmark = function() {
  +    return (this.local_.webContinuation = cocoon.createWebContinuation());
  +}
  +
  +/**
  + * Returns the bookmark continuation associated with this form, or undefined
  + * if setBookmark() has not been called.
  + * 
  + */
  +Form.prototype.getBookmark = function() {
  +    return this.local_.webContinuation;
  +}
  +
  +/**
    * Manages the display of a form and its validation.
    * @parameter uri the page uri (like in cocoon.sendPageAndWait())
  + * @parameter fun optional function which will be executed after pipeline processing. Useful
for releasing resources needed during pipeline processing but which should not become part
of the continuation
  + * @parameter ttl Time to live (in milliseconds) for the continuation created
  + * @returns The web continuation associated with submitting this form
    */
   
  -Form.prototype.showForm = function(uri, fun) {
  +Form.prototype.showForm = function(uri, fun, ttl) {
  +    if (!this.getBookmark()) {
  +        this.setBookmark();
  +    }
       var FormContext = Packages.org.apache.cocoon.woody.FormContext;
  -    this.local.webContinuation = cocoon.createWebContinuation();
       // this is needed by the WoodyTemplateTransformer:
  -    var javaWidget = this.formWidget.unwrap();;
  -    this.formWidget["woody-form"] = javaWidget;
  +    var javaWidget = this.formWidget_.unwrap();;
  +    this.formWidget_["woody-form"] = javaWidget;
       cocoon.request.setAttribute("woody-form", javaWidget);
  -    var wk = cocoon.sendPageAndWait(uri, this.formWidget, fun);
  +    var wk = cocoon.sendPageAndWait(uri, this.formWidget_, fun, ttl); 
       var formContext = 
           new FormContext(cocoon.request, javaWidget.getLocale());
       var userErrors = 0;
  -    this.formWidget.validationErrorListener = function(widget, error) {
  +    this.formWidget_.validationErrorListener = function(widget, error) {
           if (error != null) {
               userErrors++;
           }
  @@ -122,16 +146,12 @@
           this.onValidate(this);
       }
       if (!finished || userErrors > 0) {
  -        this.redisplay();
  +        cocoon.continuation = this.local_.webContinuation;
  +        this.local_.webContinuation.continuation(this.local_.webContinuation);
       }
       return wk;
   }
   
  -Form.prototype.redisplay = function() {
  -    cocoon.continuation = this.local.webContinuation;
  -    this.local.webContinuation.continuation(this.local.webContinuation);
  -}
  -
   Form.prototype.createEmptySelectionList = function(message) {
       return new Packages.org.apache.cocoon.woody.datatype.EmptySelectionList(message);
   }
  @@ -148,7 +168,7 @@
           bindingManager = cocoon.getComponent(BindingManager.ROLE);
           resolver = cocoon.getComponent(SourceResolver.ROLE);
           source = resolver.resolveURI(bindingURI);
  -        this.binding = bindingManager.createBinding(source);
  +        this.binding_ = bindingManager.createBinding(source);
       } finally {
           if (source != null) {
               resolver.release(source);
  @@ -159,15 +179,15 @@
   }
   
   Form.prototype.load = function(object) {
  -    if (this.binding == null) {
  +    if (this.binding_ == null) {
           throw new Error("Binding not configured for this form.");
       }
  -    this.binding.loadFormFromModel(this.formWidget.unwrap(), object);
  +    this.binding_.loadFormFromModel(this.formWidget_.unwrap(), object);
   }
   
   Form.prototype.save = function(object) {
  -    if (this.binding == null) {
  +    if (this.binding_ == null) {
           throw new Error("Binding not configured for this form.");
       }
  -    this.binding.saveFormToModel(this.formWidget.unwrap(), object);
  +    this.binding.saveFormToModel(this.formWidget_.unwrap(), object);
   }
  
  
  
  1.11      +12 -10    cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/flow/javascript/v2/ScriptableWidget.java
  
  Index: ScriptableWidget.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/flow/javascript/v2/ScriptableWidget.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- ScriptableWidget.java	11 Feb 2004 10:43:32 -0000	1.10
  +++ ScriptableWidget.java	16 Feb 2004 04:54:20 -0000	1.11
  @@ -238,11 +238,17 @@
           return result;
       }
   
  +    private void deleteRow(Repeater repeater, int index) {
  +        Widget row = repeater.getRow(index);
  +        formWidget.deleteWrapper(row);
  +        repeater.removeRow(index);
  +    }
  +
       public void delete(int index) {
           if (delegate instanceof Repeater) {
               Repeater repeater = (Repeater)delegate;
               if (index >= 0 && index < repeater.getSize()) {
  -                repeater.removeRow(index);
  +                deleteRow(repeater, index);
                   return;
               }
           } else if (delegate instanceof MultiValueField) {
  @@ -283,7 +289,7 @@
               int size = repeater.getSize();
               if (size > len) {
                   while (repeater.getSize() > len) {
  -                    repeater.removeRow(repeater.getSize() -1);
  +                    deleteRow(repeater, repeater.getSize() - 1);
                   }
               } else {
                   for (int i = size; i < len; ++i) {
  @@ -343,7 +349,7 @@
                   Object length = getProperty(arr, "length");
                   int len = ((Number)length).intValue();
                   for (int i = repeater.getSize(); i >= len; --i) {
  -                    repeater.removeRow(i);
  +                    deleteRow(repeater, i);
                   }
                   for (int i = 0; i < len; i++) {
                       Object elemValue = getProperty(arr, i);
  @@ -553,17 +559,13 @@
                   }    
                   for (int i = len-1; i >= 0; --i) {
                       if (index[i]) {
  -                        Widget row = repeater.getRow(i);
  -                        formWidget.deleteWrapper(row);
  -                        repeater.removeRow(i);
  +                        deleteRow(repeater, i);
                       }
                   }
               } else if (obj instanceof Number) {
                   int index = (int)Context.toNumber(obj);
                   if (index > 0 && index < repeater.getSize()) {
  -                    Widget row = repeater.getRow(index);
  -                    formWidget.deleteWrapper(row);
  -                    repeater.removeRow(index);
  +                    deleteRow(repeater, index);
                   }
               } else {
                   //...
  
  
  
  1.5       +29 -1     cocoon-2.1/src/blocks/woody/samples/v2/woody_flow_example.js
  
  Index: woody_flow_example.js
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/samples/v2/woody_flow_example.js,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- woody_flow_example.js	30 Jan 2004 23:56:18 -0000	1.4
  +++ woody_flow_example.js	16 Feb 2004 04:54:20 -0000	1.5
  @@ -152,6 +152,27 @@
       }
   
       //
  +    // By calling the Form's setBookmark() function you can set the
  +    // point in your script to return to when it is redisplayed. This
  +    // is useful if you need to acquire resources to process the 
  +    // pipeline used by the form but also have them be released
  +    // before the script is suspended e.g.:
  +    //
  +    //   form.setBookmark();
  +    //   var resource = getResource();
  +    //   form.showForm(uri, function() {
  +    //      releaseResource(resource);
  +    //      resource = null;
  +    //   });
  +    //
  +    // Each time the form is redisplayed (e.g. during validation) your
  +    // script will resume right after the call to setBookmark() and
  +    // the resource will be reacquired.
  +    //
  +    form.setBookmark();
  +
  +    print("hit bookmark");
  +    //
       // You can set additional properties on any widget that will
       // be accessible in the pipeline (e.g. with JXTemplateGenerator)
       //
  @@ -161,7 +182,14 @@
       // showForm() repeatedly sends the form to the browser and doesn't return
       // until validation is complete.
       //
  -    form.showForm("form1-display-pipeline");
  +    form.showForm("form1-display-pipeline", function() {
  +                    // if you supply a function as the second argument
  +                    // to showForm() it will be called after pipeline
  +                    // processing, but before the script is suspended.
  +                    // This is where you would release resources you
  +                    // don't want to become part of the continuation.
  +                    delete wid.buttonName;
  +                  });
       print("cowheight = "+wid.cowheight.value);
   }
   
  
  
  

Mime
View raw message