sylvain     2003/09/29 05:56:05

  Modified:    src/blocks/woody/java/org/apache/cocoon/woody/event/impl
                        JavaScriptWidgetListener.java
               src/blocks/woody/java/org/apache/cocoon/woody/flow/javascript
                        woody2.js
               src/java/org/apache/cocoon/components/flow/javascript/fom
                        FOM_Cocoon.java FOM_JavaScriptFlowHelper.java
                        FOM_JavaScriptInterpreter.java
  Log:
  Propagate the flowscript scope ("cocoon" and session-global objects) to 
javascript woody event handlers
  
  Revision  Changes    Path
  1.2       +21 -9     
cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/event/impl/JavaScriptWidgetListener.java
  
  Index: JavaScriptWidgetListener.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/event/impl/JavaScriptWidgetListener.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JavaScriptWidgetListener.java     24 Sep 2003 20:47:06 -0000      1.1
  +++ JavaScriptWidgetListener.java     29 Sep 2003 12:56:05 -0000      1.2
  @@ -52,6 +52,8 @@
   
   import org.apache.avalon.framework.CascadingRuntimeException;
   import org.apache.cocoon.components.CocoonComponentManager;
  +import org.apache.cocoon.components.flow.FlowHelper;
  +import 
org.apache.cocoon.components.flow.javascript.fom.FOM_JavaScriptFlowHelper;
   import org.apache.cocoon.environment.ObjectModelHelper;
   import org.apache.cocoon.environment.Request;
   import org.apache.cocoon.woody.event.ActionEvent;
  @@ -93,12 +95,9 @@
           
       }
       
  -    public static Scriptable getParentScope() {
  +    public static Scriptable getParentScope(Request request) {
           // Try to get the flowscript scope
  -        // FIXME: remove this ugly hack and get the request from the Avalon 
context once
  -        // listener builder are real components
  -        Request request = 
ObjectModelHelper.getRequest(CocoonComponentManager.getCurrentEnvironment().getObjectModel());
  -        Scriptable parentScope = 
(Scriptable)request.getAttribute("flow-script-scope");
  +        Scriptable parentScope = 
(Scriptable)request.getAttribute(FOM_JavaScriptFlowHelper.FOM_SCOPE);
   
           if (parentScope != null) {
               return parentScope;
  @@ -114,15 +113,23 @@
           Context ctx = Context.enter();
           try {
               
  -            Scriptable parentScope = getParentScope();
  +            // FIXME: remove this ugly hack and get the request from the 
Avalon context once
  +            // listener builder are real components
  +            Request request = 
ObjectModelHelper.getRequest(CocoonComponentManager.getCurrentEnvironment().getObjectModel());
  +
  +            Scriptable parentScope = getParentScope(request);
               
               // Create a new local scope for the event listener variables
               Scriptable scope = ctx.newObject(parentScope);
  +            scope.setPrototype(parentScope);
               scope.put("event", scope, Context.toObject(event, scope));
               
  -            // FIXME: I would also put the widget as "this", but there seems 
to be another "this" in the way...
  -            //scope.put("this", scope, Context.toObject(event.getSource(), 
scope));
  -
  +            // Add the biz data that was passed to showForm()
  +            Object viewData = 
request.getAttribute(FlowHelper.CONTEXT_OBJECT);
  +            if (viewData != null) {
  +                scope.put("viewData", scope, viewData);
  +            }
  +            
               script.exec(ctx, scope);
               
           } catch(RuntimeException re) {
  @@ -133,6 +140,11 @@
           } finally {
               Context.exit();
           }
  +    }
  +    
  +    public static final void traceHack(Object obj) {
  +        System.err.println("trace of " + obj.getClass().getName());
  +        System.err.println(obj);
       }
       
       public static class JSActionListener extends JavaScriptWidgetListener 
implements ActionListener {
  
  
  
  1.3       +5 -1      
cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/flow/javascript/woody2.js
  
  Index: woody2.js
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/flow/javascript/woody2.js,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- woody2.js 25 Sep 2003 17:37:30 -0000      1.2
  +++ woody2.js 29 Sep 2003 12:56:05 -0000      1.3
  @@ -141,6 +141,10 @@
           var formContext = 
               
Packages.org.apache.cocoon.woody.flow.javascript.WoodyFlowHelper.getFormContext(cocoon,
 this.locale);
   
  +             // Prematurely add the bizData as a request attribute so that 
event listeners can use it
  +             // (the same is done by cocoon.sendPage())
  +             
cocoon.request.setAttribute(Packages.org.apache.cocoon.components.flow.FlowHelper.CONTEXT_OBJECT,
 bizData);
  +
                finished = this.form.process(formContext);
           
           // Additional flow-level validation
  
  
  
  1.12      +5 -1      
cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_Cocoon.java
  
  Index: FOM_Cocoon.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_Cocoon.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- FOM_Cocoon.java   2 Sep 2003 20:49:21 -0000       1.11
  +++ FOM_Cocoon.java   29 Sep 2003 12:56:05 -0000      1.12
  @@ -132,6 +132,10 @@
       }
   
       void invalidate() {
  +        // Clear the scope attribute
  +        
this.getRequest().removeAttribute(FOM_JavaScriptFlowHelper.FOM_SCOPE);
  +        
  +        // Cleanup everything
           this.request = null;
           this.response = null;
           this.session = null;
  
  
  
  1.2       +5 -0      
cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptFlowHelper.java
  
  Index: FOM_JavaScriptFlowHelper.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptFlowHelper.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FOM_JavaScriptFlowHelper.java     8 Jul 2003 05:48:52 -0000       1.1
  +++ FOM_JavaScriptFlowHelper.java     29 Sep 2003 12:56:05 -0000      1.2
  @@ -79,6 +79,11 @@
           "cocoon.flow.js.fom.FOM_Context";
       public static final String FOM_WEB_CONTINUATION = 
           "cocoon.flow.js.fom.FOM_WebContinuation";
  +    /**
  +     * The parent scope to be used by nested scripts (e.g. Woody event 
handlers)
  +     */
  +    public static final String FOM_SCOPE =
  +        "cocoon.flow.js.fom.FOM_Scope";
   
       /** 
        * Return the JS "Packages" property (that gives access to Java
  
  
  
  1.10      +7 -1      
cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java
  
  Index: FOM_JavaScriptInterpreter.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- FOM_JavaScriptInterpreter.java    24 Sep 2003 20:38:09 -0000      1.9
  +++ FOM_JavaScriptInterpreter.java    29 Sep 2003 12:56:05 -0000      1.10
  @@ -530,6 +530,9 @@
               try {
                   setupContext(environment, context, thrScope);
                   cocoon = (FOM_Cocoon)thrScope.get("cocoon", thrScope);
  +                
  +                // Register the current scope for scripts indirectly called 
from this function
  +                
cocoon.getRequest().setAttribute(FOM_JavaScriptFlowHelper.FOM_SCOPE, thrScope);
                   if (enableDebugger) {
                       if (!getDebugger().isVisible()) {
                           // only raise the debugger window if it isn't 
already visible
  @@ -612,6 +615,9 @@
           synchronized (kScope) {
               FOM_Cocoon cocoon = (FOM_Cocoon)kScope.get("cocoon", kScope);
               cocoon.setup(this, environment, manager, getLogger());
  +            // Register the current scope for scripts indirectly called from 
this function
  +            
cocoon.getRequest().setAttribute(FOM_JavaScriptFlowHelper.FOM_SCOPE, kScope);
  +
               if (enableDebugger) {
                   getDebugger().setVisible(true);
               }
  
  
  

Reply via email to