Author: adrianc
Date: Tue Jan 29 21:49:25 2008
New Revision: 616639
URL: http://svn.apache.org/viewvc?rev=616639&view=rev
Log:
Added the ability to call simple methods from screen widgets. This eliminates
the need to define a service to call a simple method.
Just use the <script location="component://... .xml#methodName" syntax. The
simple method call works just like a service event - the result Map elements
are copied into the screen context.
Note that this enhancement should NOT be used to circumvent existing services -
since many processes depend upon SECAs, which won't get executed using this
screen widget operation.
Modified:
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenAction.java
Modified:
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenAction.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenAction.java?rev=616639&r1=616638&r2=616639&view=diff
==============================================================================
---
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenAction.java
(original)
+++
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenAction.java
Tue Jan 29 21:49:25 2008
@@ -51,6 +51,9 @@
import org.ofbiz.entity.finder.ByConditionFinder;
import org.ofbiz.entity.finder.EntityFinderUtil;
import org.ofbiz.entity.finder.PrimaryKeyFinder;
+import org.ofbiz.minilang.MiniLangException;
+import org.ofbiz.minilang.SimpleMethod;
+import org.ofbiz.minilang.method.MethodContext;
import org.ofbiz.service.DispatchContext;
import org.ofbiz.service.GenericServiceException;
import org.ofbiz.service.ModelService;
@@ -386,12 +389,23 @@
try {
BshUtil.runBshAtLocation(location, context);
} catch (GeneralException e) {
- String errMsg = "Error running BSH script at location [" +
location + "]: " + e.toString();
- // throwing nested exception instead of logging full
detail: Debug.logError(e, errMsg, module);
- throw new GeneralException(errMsg, e);
+ throw new GeneralException("Error running BSH script at
location [" + location + "]", e);
+ }
+ } else if (location.contains(".xml#")) {
+ String xmlResource =
ScreenFactory.getResourceNameFromCombined(location);
+ String methodName =
ScreenFactory.getScreenNameFromCombined(location);
+ Map localContext = FastMap.newInstance();
+ localContext.putAll(context);
+ DispatchContext ctx =
this.modelScreen.getDispatcher(context).getDispatchContext();
+ MethodContext methodContext = new MethodContext(ctx,
localContext, null);
+ try {
+ SimpleMethod.runSimpleMethod(xmlResource, methodName,
methodContext);
+ context.putAll(methodContext.getResults());
+ } catch (MiniLangException e) {
+ throw new GeneralException("Error running simple method at
location [" + location + "]", e);
}
} else {
- throw new GeneralException("For screen script actions the
script type is not yet support for location:" + location);
+ throw new GeneralException("For screen script actions the
script type is not yet supported for location: [" + location + "]");
}
}
}