Adding Logic to Workflows with Listeners and Process Variables
So far you've seen that a process can be modeled as a collection of nodes connected via paths or transitions. A common requirement is to be able to execute some code or business logic at certain points within the process. For example, maybe you want to send an e-mail or want to increment a counter that keeps track of how many times a node has been executed. We already used the concept of service tasks to execute some codes, but now we are going to use event listeners.
An event mechanism has been introduced in Activiti to get notified when various events occur within the engine. In our use case, we are going to focus on the Task Listener. A task listener is used to execute custom Java logic or an expression upon the occurrence of a certain task-related event. Using the Activiti Designer, you can create listeners on user tasks where you'll be able to configure:
The event nature: create, assignment, complete, or all.
The event type...