How to create a variable JavaServiceTask ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2012 11:18 AM

I'm creating a new workflow with our cool activiti stuff and wondering if that's possible to create a javaServiceTask with a variable activiti class to be used in multiple workflow instance with different goals. For example, the first workflow instance would initialize "myVariable" to call MyFirstClass.java in my javaServiceTask, and, at the contrary, the second instance would call "MySecondClass.java" (for example, because the creating users don't have the same rights, so the called classes are not the same or because i want to create a tool to generate workflow templates but where you can specify in a previous task what you want this template do).
In the userGuide, i've seen something so similar for an other task type :
<businessRuleTask id="businessRuleTask" activiti:class="${MyRuleServiceDelegate}" />
And i was trying to do something close for my javaServiceTask :
<serviceTask id="javaService2" name="Java service invocation" activiti:class="${testVariable}"></serviceTask>
But it generates two errors in my bpmn20 validation :
Multiple annotations found at this line:
- cvc-attribute.3: The value '${testVariable}' of attribute 'activiti:class' on element 'serviceTask' is not valid with respect to its type, 'null'.
- cvc-pattern-valid: Value '${testVariable}' is not facet-valid with respect to pattern '([a-z]{2,3}(\.[a-zA-Z][a-zA-Z_$0-9]*)*)\.([A-Z][a-zA-Z_$0-9]*)' for type '#AnonType_class'.
Then… does anyone has an idea how to do it ?
Thanks for your time

- Labels:
-
Archive
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2012 02:27 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2012 04:45 AM
GRAVE: Error while closing command context
org.activiti.engine.ActivitiException: couldn't instantiate class ${testVariable}
Well maybe that's impossible
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2012 04:50 AM
activiti:class="${testVariable}"
activiti:class should be a string literal, containing a class-name… If you want to have a dynamic JavaDelegate, take a look at activiti:expression en activiti:delegateExpression in the user guide.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2012 06:02 AM
Could you just give me an example of a very simple workflow with two javaServiceTask ?
- The first javaServiceTask would call a class with activiti:class where you create a process variable "toto" which contains "org.activiti.MyClass". Like :
public class SetterTest implements JavaDelegate {
private static final String VARIABLE_NAME = "toto";
public void execute(DelegateExecution execution) {
String var = "org.activiti.MyClass";
execution.setVariable(VARIABLE_NAME, var);
}
}
- And the second javaServiceTask would call the toto variable class.If you can do it, you would resolve my problem because i'm really out of ideas right now

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2012 06:39 AM
In that case, add a POJO instance as a process-variable (make sure it implements Serializable) instead of the classname. Afterwards, use activiti:delegateExpression="${myVariable.doStuff()}" (supposing the POJO has a doStuff method).
Please note, using a serializable as variable works, but not sure what your use case would be…
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2012 07:17 AM
It works as it enters my code but after executing it, i have an error !
GRAVE: Error while closing command context
org.activiti.engine.ActivitiException: Delegate expression ${myVariable.execute()} did not resolve to an implementation of interface org.activiti.engine.impl.pvm.delegate.ActivityBehavior nor interface org.activiti.engine.delegate.JavaDelegate
That s strange because my class MyClass.java which is stored in myVariable implements serializable (as you told me) and JavaDelegate…
Where is the problem so ?
One other question : If i want to pass process or task parameters to my method doStuff(), can i do it by creating them in the task or process and just call : activiti:delegateExpression="${myVariable.doStuff(param1, param2, …)}" or do i have to do something different ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2012 07:47 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2012 07:55 AM
public class ManagerTest implements Serializable, JavaDelegate {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public void execute(DelegateExecution arg0) throws Exception {
int a = 1;
}
public void test() throws Exception {
int a = 1;
}
}
I m really sorry for all that work i m giving to you, i really feel as a newb :'(
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2012 03:55 AM
