cancel
Showing results for 
Search instead for 
Did you mean: 

Expression Evaluation using activiti Expression packages

k_kunti
Champ in-the-making
Champ in-the-making
Dear All

I am looking for approach for using activiti's expression evaluation packages in my Custom JSF based web application (where I Activiti JARS). What is the best way to call the activiti expression evaluation classes (which interfaces to use?). If anyone have tried this please pass some pointers.

Thanks in advance
Krish

I was looking at the code and it looks like ExpressionManager Class in package org.activiti.engine.impl.el; package is used for runtime evaluation of expression (the code commenting says that Smiley Happy )…It will be great if someone from the Dev team can guide regarding the call sequence during runtime evaluation of expression.
9 REPLIES 9

frederikherema1
Star Contributor
Star Contributor
Hi,

Have a look at org.activiti.engine.impl.el.JuelExpression and org.activiti.engine.impl.el.ExpressionManager. An expression is first created (parsed) using expression-manager and when needed it's evaluated against an VariableScope (eg. the delegateExecution).

To obtain the expression-manager, use

ExpressionManager expressionManager = processEngine.getProcessEngineConfiguration().getExpressionManager();

To parse an expression, use:

expressionManager.createExpression("${myVar + 1}");

You can plug in a custom ExpressionManager, example of this is in ProcessEngineFactoryBean and SpringExpressionManager.

k_kunti
Champ in-the-making
Champ in-the-making
hi Frederik

Thanks a ton for the quick response.

Krish

k_kunti
Champ in-the-making
Champ in-the-making
Hi Frederik

It will be a big help if you can guide me regarding ..

In case of using a default process engine:
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

How to get expression manager–> create expression–> evaluate expression

Thank you
Krish

frederikherema1
Star Contributor
Star Contributor
To get the expressionmanager, cast the ProcessEngine to ProcessEngineImpl and use the code I suggested above:


ExpressionManager expressionManager = ((ProcessEngineImpl)processEngine).getProcessEngineConfiguration().getExpressionManager();
Expression myEx = expressionManager.createExpression("${myVar + 1}");
Object result = myEx.getValue(variableScope);

k_kunti
Champ in-the-making
Champ in-the-making
Thanks gain for the help Smiley Happy

k_kunti
Champ in-the-making
Champ in-the-making
Hi Frederik

One more help  ::

How to get an handle of DelegateExecution (or create it using API) from outside the Activiti Instance say from a Java class that will pass the parameters to Activiti.

Thank you Smiley Happy Smiley Happy

Krish

frederikherema1
Star Contributor
Star Contributor
Krish,

The activiti-expressions are designed to be evaluated in the process-context (DelegateExecution), so getting a hold of one through API is inpossible.
What's the point of using activiti-expression handling when you're not using it inside activiti process? If you want to resolve espressions based on non-process stuff, you should just use JUEL as a library for that or leverage the JUEL present in the activiti codebase. If you do this, you shouldn't use the ExpressionManager, but create your ow ELResolvers that access the data you want and use these to evaluate the expressions. a couple of pointers:

org.activiti.engine.impl.javax.el.ValueExpression
org.activiti.engine.impl.javax.el.ExpressionFactory

org.activiti.engine.impl.el.JuelExpression
org.activiti.engine.impl.el.ExpressionManager

ValueExpression valueExpression = expressionFactory.createValueExpression(parsingElContext, expression, Object.class);
valueExpression.getValue(elContext);

k_kunti
Champ in-the-making
Champ in-the-making
Hi Frederik

I wanted to use JSF EL along with custom EL (the one used in activiti); so that I will be able to populate the JSF based forms outside the activiti engine (albeit with activiti engine based process / task level values ).

In activiti Ftl based froms are used to generate HTML where the engine has an handle to the form at the execution time… however in a JSF based application Activiti engine will not have an handle to a form and hence the requirement of evaluating existing activiti based expression syntax in JSF from from activiti engine run time instance values.

Please suggest what is the best way forward.

Thank you
krish

frederikherema1
Star Contributor
Star Contributor
if you want to render forms in JSF, independent of activiti you should hook an ELResover (EL API, not activiti) into your JSF. This resolver can use the map of variables returned by the API-calls:

runtimeService.getVariables(processInstance.getId());
taskService.getVariables(Local)(task.getId());