jBPM task nodes are designed to interact with users. The main utility of this kind of nodes is to treat forms data. When a process arrives to a task node, it waits until the required actor makes an action.
Task nodes are the most complex nodes, you will have to implement two handlers: one to assign the task to an actor and another to define this task.
Lets start with the AssignmentHandler.
Using Eclipse interface you can setup your task node as it follows, specifying where is your class.
ExampleAssign must be something like that:
public class ExampleAssign implements AssignmentHandler{....}
Implementing this interface means that you will have to develop an assign method.
public void assign(Assignable assignable, ExecutionContext executionContext) throws Exception;
Inside this function you will need to assign the current task(assignable) to somebody using assignable.setActorId(actor).
The responsibility of this method does not finish here. When you came into a task node, you will have to save all process state and variables to stop the process. You can not assume that the actor will be waiting for the assignment and neither you will want to wait until he logins into the application. System must continue running normally.
Calling this two functions you will save the execution context into database using Hibernate.
executionContext.getJbpmContext().save(executionContext.getTaskInstance());executionContext.getJbpmContext().close();
Next step is to configure and develop a task controller.
This class must look like this:
public class ControlExample implements TaskControllerHandler{...}
It must implement this two methods:
public void initializeTaskVariables(TaskInstance taskInstance, ContextInstance contextInstance, Token token);public void submitTaskVariables(TaskInstance taskInstance, ContextInstance contextInstance, Token token);
First one is used to initialize task variables, you can set default values or whatever you need.
Second one treat all task variables. This is the main function of the task nodes. Remember to invoke token.signal(); when all treatment is done.
Thats all, but you will be wondering how does it work, how can I wake up the sleeping process…
Somewhere in your program, in a from treatment function or in a button event, for example, you will have to make some extra work. You will need to identify the user and the process instance. Functions like:
List l = jbpmContext.getTaskMgmtSession().findTaskInstances(user);
will help you. When you have the correct TaskInstance you will have to invoke ti.end();. This function will wake up the process and the associated state from database using Hibernate and call submitTaskVariables(). Workflow will continue normally at this point.
Thats all I wanted to explain of jBPM nodes. I’m not normally using Fork and Join nodes in my projects, so I will not write a guide for them. They are very easy to include in your workflows but if somebody ask for it, I will write a mini how-to.





April 2nd, 2008 at 9:40 pm
thank you so much , your info helps me at my project
April 3rd, 2008 at 1:26 pm
You’re welcome.
Help other people where nobody helped me is one of objectives of this blog.
April 9th, 2008 at 10:45 am
Hi,
can you write on your blog the process definition file and the TaskControllerHandler source file?
That will be very helpful to me.
Massimo.
April 9th, 2008 at 12:30 pm
I am really busy this week, can you wait?
ps: jbpm-jpdl-3.2.2 zip include some examples about these handlers.
June 18th, 2008 at 11:36 pm
I have a question?
for example this List l , which you was made, can be able to show in a form? can be able to show in web??
Thank ,, I tried to do this but doesn’t work.
George.
June 19th, 2008 at 1:26 pm
@george
You can try something like that to print tasks names and descriptions:
List l = jbpmContext.getTaskMgmtSession().findTaskInstances(user);
TaskInstance ti=null;
ListIterator li = l.listIterator();
while (li.hasNext()){
ti = (TaskInstance)li.next();
System.out.println(ti.getName());
System.out.println(ti.getDescription());
}
Create some functions to get whatever you want and call them from your webpage to print them out.
Pigui
September 30th, 2008 at 5:34 pm
I have an issue with the jbpm console. Each time a task-node has ended, the console throws up a comment dialog box. I’m using the 3.2.2 jbpm-console on JBoss 4.2.2.GA.
Two questions.
1. Is there a way to short circuit that or allow me to control it so I can make it show up at the bottom of an input web form?
2. I know the transition state is taken care of by the process definition, is there a way I can encode the submitButton to not only finish/end the task-node, but also redirect the page elsewhere? Would I write my own java action handler to handle that and how?
Thanks.
Brian
October 2nd, 2008 at 7:48 am
@Brian
I never tried to hack jbpm console. Nowadays I have not installed it so I can’t read some code to help you. I’m sorry.
October 2nd, 2008 at 3:34 pm
I figured out #2 by editing task.xhtml and I’m sure I can play around with it more to do #1 in my previous post.
I’m looking through the jbpm javadoc and there doesn’t seem be a call to get the next task.
I’m trying to do 2 things.
1. When a task-node has been completed, If the next task is to the same Actor, then go to the next task instance page.
2. If not, then display who the next task is queued to.
I imagine I will have get the list of tasks for the current process instance, loop through and locate the next task-node then probably will have to make a db call to get the actorid/pooled actors to see if it matches the current Actor.
Any insight would be appreciated.
Thanks.
Brian
October 3rd, 2008 at 7:56 am
@Brian
May it can help you.
You can invoke getActorIdExpression() over a Task instance to get it’s actor.
Another useful function I often use is: jbpmContext.getTaskMgmtSession().findTaskInstances(user);
to list all user pendant tasks.
October 16th, 2008 at 5:54 am
Hi,
As i started developing a jbpm process project, iam unable to give the variables a valid name. if i give channelname as variable name, it is talking it as variable 1…….etc. why is this happening? pls help me…..
January 12th, 2009 at 9:36 am
how do we get the next actor of the workflor programaticaly? i need to get the next actor to assign for the job. because the process definition is dynamic. so i cant hardcord the assign statement with the user.
March 18th, 2009 at 1:24 pm
Hey there,
To starrt with, lemme tel u..You’re doin one awesome job. Im a newbie to jbpm..hav been usin it since past 20 days. Im jus too cnfused with action and event handling.
Can u pl send me some demo case study which can be imported in eclipse, so that I can understand thwe working, integration and coding part of jBPM. please
Am wrking on a life insurance case study that has to be automated usin jbpm. like acepting data of customer, check if it already exists in database, registerin user, callin webservices n a whole lot. Im stuck up badly.
Pl help asap.
Thanks in advance
March 19th, 2009 at 7:13 am
Hey,
I have been try to pass the value of a variable between different nodes.
the code i rote was:
String password = (String) exe.getContextInstance().getVariable (”password”);
where password is the process variable that I defined in the controller of the node above this node.
however no value is getting transferred below. Pl help me. Im stuck up badly.
Also, when i create process variables in the controller of a tasknode,and generate its correspondin form, the variables don’t come in the form by default. I have to write n save them agn in the form.
Pl help me what to do.
Pls pls..
Thanks in advance
March 19th, 2009 at 4:38 pm
@PM,
Hi,
There are several small examples JBPM inside the package and at jboss.org.
To invoke getVariable method correctly, setVariable method must be called before.
Hope it helps.
March 20th, 2009 at 2:23 pm
Hey there,
Thanks for the reply. I have proceeded in my proj aftr your help, though still stuk up wid sum issues.
Pls help me wd this 1 problm:
when I add a variable in the task node, n generate form corrsponding to that node, then the default variables created are not visible in the variable list. I have to create them agn, whch means value passin of variables does not happen btwn nodes.
can u pls throw sum light on the issue?
Thanks in advance
August 3rd, 2009 at 2:21 pm
Hi,
I have a little confusion with Task Node & Node. So I have couple of question .
1. I have to design a TaskNode (Ex. NodeX) . It has two transition names”YES” and “NO” . Now the appropriate transition should work according to the use input in TaskNode NodeX. Now how to achieve that.
August 3rd, 2009 at 5:27 pm
Hi @Prajatna
why don’t you try a decision node, it looks like it fits better to your needs. Look at this other post.
http://blogs.dfwikilabs.org/pigui/2008/02/14/jbpm-decision-nodes-development/