svn commit: r1307606 - in /ofbiz/branches/20120329_portletWidget/framework: minilang/src/org/ofbiz/minilang/method/ widget/src/org/ofbiz/widget/ widget/src/org/ofbiz/widget/form/ widget/src/org/ofbiz/widget/screen/

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1307606 - in /ofbiz/branches/20120329_portletWidget/framework: minilang/src/org/ofbiz/minilang/method/ widget/src/org/ofbiz/widget/ widget/src/org/ofbiz/widget/form/ widget/src/org/ofbiz/widget/screen/

erwan
Author: erwan
Date: Fri Mar 30 20:53:28 2012
New Revision: 1307606

URL: http://svn.apache.org/viewvc?rev=1307606&view=rev
Log:
OFBIZ-4688 patch needed to make everything work

Modified:
    ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/MethodContext.java
    ofbiz/branches/20120329_portletWidget/framework/widget/src/org/ofbiz/widget/ModelWidgetAction.java
    ofbiz/branches/20120329_portletWidget/framework/widget/src/org/ofbiz/widget/form/ModelFormAction.java
    ofbiz/branches/20120329_portletWidget/framework/widget/src/org/ofbiz/widget/screen/ModelScreenAction.java

Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/MethodContext.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/MethodContext.java?rev=1307606&r1=1307605&r2=1307606&view=diff
==============================================================================
--- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/MethodContext.java (original)
+++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/MethodContext.java Fri Mar 30 20:53:28 2012
@@ -28,6 +28,7 @@ import javax.servlet.http.HttpServletRes
 
 import javolution.util.FastMap;
 
+import org.ofbiz.base.util.UtilGenerics;
 import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilHttp;
 import org.ofbiz.base.util.collections.FlexibleMapAccessor;
@@ -90,9 +91,21 @@ public class MethodContext implements It
         }
     }
 
+    // constructor to use minilang as script call in screen action
+    public MethodContext(DispatchContext ctx, Map<String, ? extends Object> context) {
+        this.methodType = MethodContext.SERVICE;
+        Map<String, Object> parametersCtx = UtilGenerics.checkMap(context.get("parameters"));
+        this.parameters = UtilMisc.makeMapWritable(parametersCtx);
+        putAllEnv(context);
+        loadThis(ctx, context, null);
+    }
+
     public MethodContext(DispatchContext ctx, Map<String, ? extends Object> context, ClassLoader loader) {
         this.methodType = MethodContext.SERVICE;
         this.parameters = UtilMisc.makeMapWritable(context);
+        loadThis(ctx, context, loader);
+    }
+    private void loadThis(DispatchContext ctx, Map<String, ? extends Object> context, ClassLoader loader) {
         this.loader = loader;
         this.locale = (Locale) context.get("locale");
         this.timeZone = (TimeZone) context.get("timeZone");

Modified: ofbiz/branches/20120329_portletWidget/framework/widget/src/org/ofbiz/widget/ModelWidgetAction.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/widget/src/org/ofbiz/widget/ModelWidgetAction.java?rev=1307606&r1=1307605&r2=1307606&view=diff
==============================================================================
--- ofbiz/branches/20120329_portletWidget/framework/widget/src/org/ofbiz/widget/ModelWidgetAction.java (original)
+++ ofbiz/branches/20120329_portletWidget/framework/widget/src/org/ofbiz/widget/ModelWidgetAction.java Fri Mar 30 20:53:28 2012
@@ -389,31 +389,37 @@ public abstract class ModelWidgetAction
     }
 
     public static class Script extends ModelWidgetAction {
-        protected String location;
-        protected String method;
+        protected FlexibleStringExpander scriptLocationExdr;
 
         public Script(ModelWidget modelWidget, Element scriptElement) {
             super (modelWidget, scriptElement);
-            String scriptLocation = scriptElement.getAttribute("location");
-            this.location = WidgetWorker.getScriptLocation(scriptLocation);
-            this.method = WidgetWorker.getScriptMethodName(scriptLocation);
+            this.scriptLocationExdr = FlexibleStringExpander.getInstance(scriptElement.getAttribute("location"));
         }
 
         @Override
         public void runAction(Map<String, Object> context) throws GeneralException {
+            Locale locale = (Locale) context.get("locale");
+            String scriptLocation = this.scriptLocationExdr.expandString(context, locale);
+            String location = WidgetWorker.getScriptLocation(scriptLocation);
+            String method = WidgetWorker.getScriptMethodName(scriptLocation);
             if (location.endsWith(".xml")) {
-                Map<String, Object> localContext = FastMap.newInstance();
-                localContext.putAll(context);
                 DispatchContext ctx = WidgetWorker.getDispatcher(context).getDispatchContext();
-                MethodContext methodContext = new MethodContext(ctx, localContext, null);
+                MethodContext methodContext = new MethodContext(ctx, context);
                 try {
                     SimpleMethod.runSimpleMethod(location, method, methodContext);
-                    context.putAll(methodContext.getResults());
+                    Map<String, Object> resultContext = methodContext.getEnv("widget");
+                    if (UtilValidate.isNotEmpty(resultContext)){
+                        context.putAll(resultContext);
+                    }
+                    Map<String, Object> parametersUp = methodContext.getParameters();
+                    if (UtilValidate.isNotEmpty(parametersUp)){
+                        context.put("parameters",parametersUp);
+                    }
                 } catch (MiniLangException e) {
                     throw new GeneralException("Error running simple method at location [" + location + "]", e);
                 }
             } else {
-                ScriptUtil.executeScript(this.location, this.method, context);
+                ScriptUtil.executeScript(location, method, context);
             }
         }
     }

Modified: ofbiz/branches/20120329_portletWidget/framework/widget/src/org/ofbiz/widget/form/ModelFormAction.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/widget/src/org/ofbiz/widget/form/ModelFormAction.java?rev=1307606&r1=1307605&r2=1307606&view=diff
==============================================================================
--- ofbiz/branches/20120329_portletWidget/framework/widget/src/org/ofbiz/widget/form/ModelFormAction.java (original)
+++ ofbiz/branches/20120329_portletWidget/framework/widget/src/org/ofbiz/widget/form/ModelFormAction.java Fri Mar 30 20:53:28 2012
@@ -273,31 +273,37 @@ public abstract class ModelFormAction {
     }
 
     public static class Script extends ModelFormAction {
-        protected String location;
-        protected String method;
+        protected FlexibleStringExpander scriptLocationExdr;
 
         public Script(ModelForm modelForm, Element scriptElement) {
             super (modelForm, scriptElement);
-            String scriptLocation = scriptElement.getAttribute("location");
-            this.location = WidgetWorker.getScriptLocation(scriptLocation);
-            this.method = WidgetWorker.getScriptMethodName(scriptLocation);
+            this.scriptLocationExdr = FlexibleStringExpander.getInstance(scriptElement.getAttribute("location"));
         }
 
         @Override
         public void runAction(Map<String, Object> context) {
+            Locale locale = (Locale) context.get("locale");
+            String scriptLocation = this.scriptLocationExdr.expandString(context, locale);
+            String location = WidgetWorker.getScriptLocation(scriptLocation);
+            String method = WidgetWorker.getScriptMethodName(scriptLocation);
             if (location.endsWith(".xml")) {
-                Map<String, Object> localContext = FastMap.newInstance();
-                localContext.putAll(context);
                 DispatchContext ctx = this.modelForm.dispatchContext;
-                MethodContext methodContext = new MethodContext(ctx, localContext, null);
+                MethodContext methodContext = new MethodContext(ctx, context);
                 try {
                     SimpleMethod.runSimpleMethod(location, method, methodContext);
-                    context.putAll(methodContext.getResults());
+                    Map<String, Object> resultContext = methodContext.getEnv("widget");
+                    if (UtilValidate.isNotEmpty(resultContext)){
+                        context.putAll(resultContext);
+                    }
+                    Map<String, Object> parametersUp = methodContext.getParameters();
+                    if (UtilValidate.isNotEmpty(parametersUp)){
+                        context.put("parameters",parametersUp);
+                    }
                 } catch (MiniLangException e) {
                     throw new IllegalArgumentException("Error running simple method at location [" + location + "]", e);
                 }
             } else {
-                ScriptUtil.executeScript(this.location, this.method, context);
+                ScriptUtil.executeScript(location, method, context);
             }
         }
     }

Modified: ofbiz/branches/20120329_portletWidget/framework/widget/src/org/ofbiz/widget/screen/ModelScreenAction.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/widget/src/org/ofbiz/widget/screen/ModelScreenAction.java?rev=1307606&r1=1307605&r2=1307606&view=diff
==============================================================================
--- ofbiz/branches/20120329_portletWidget/framework/widget/src/org/ofbiz/widget/screen/ModelScreenAction.java (original)
+++ ofbiz/branches/20120329_portletWidget/framework/widget/src/org/ofbiz/widget/screen/ModelScreenAction.java Fri Mar 30 20:53:28 2012
@@ -401,31 +401,37 @@ public abstract class ModelScreenAction
 
     @Deprecated
     public static class Script extends ModelScreenAction {
-        protected String location;
-        protected String method;
+        protected FlexibleStringExpander scriptLocationExdr;
 
         public Script(ModelScreen modelScreen, Element scriptElement) {
             super (modelScreen, scriptElement);
-            String scriptLocation = scriptElement.getAttribute("location");
-            this.location = WidgetWorker.getScriptLocation(scriptLocation);
-            this.method = WidgetWorker.getScriptMethodName(scriptLocation);
+            this.scriptLocationExdr = FlexibleStringExpander.getInstance(scriptElement.getAttribute("location"));
         }
 
         @Override
         public void runAction(Map<String, Object> context) throws GeneralException {
+            Locale locale = (Locale) context.get("locale");
+            String scriptLocation = this.scriptLocationExdr.expandString(context, locale);
+            String location = WidgetWorker.getScriptLocation(scriptLocation);
+            String method = WidgetWorker.getScriptMethodName(scriptLocation);
             if (location.endsWith(".xml")) {
-                Map<String, Object> localContext = FastMap.newInstance();
-                localContext.putAll(context);
                 DispatchContext ctx = this.modelScreen.getDispatcher(context).getDispatchContext();
-                MethodContext methodContext = new MethodContext(ctx, localContext, null);
+                MethodContext methodContext = new MethodContext(ctx, context);
                 try {
                     SimpleMethod.runSimpleMethod(location, method, methodContext);
-                    context.putAll(methodContext.getResults());
+                    Map<String, Object> resultContext = methodContext.getEnv("widget");
+                    if (UtilValidate.isNotEmpty(resultContext)){
+                        context.putAll(resultContext);
+                    }
+                    Map<String, Object> parametersUp = methodContext.getParameters();
+                    if (UtilValidate.isNotEmpty(parametersUp)){
+                        context.put("parameters",parametersUp);
+                    }
                 } catch (MiniLangException e) {
                     throw new GeneralException("Error running simple method at location [" + location + "]", e);
                 }
             } else {
-                ScriptUtil.executeScript(this.location, this.method, context);
+                ScriptUtil.executeScript(location, method, context);
             }
         }
     }