how to add a custom task listener through java code?

cancel
Showing results for 
Search instead for 
Did you mean: 
goutham_pn
Member II

how to add a custom task listener through java code?

Jump to solution

I'm building the usertask and servicetask dynamically

default UserTask createUserTask(String id, String name, String assignee) {
UserTask userTask = new UserTask();
userTask.setName(name);
userTask.setId(id);
userTask.setAssignee(assignee);
return userTask;
}

default ServiceTask createServiceTask(String id, String name, boolean asyn) {
ServiceTask serviceTask = new ServiceTask();
serviceTask.setName(name);
serviceTask.setId(id);
serviceTask.setAsynchronous(asyn);
ActivitiListener al = new ActivitiListener();

ExtensionAttribute ea = new ExtensionAttribute("activti", "abc");
// serviceTask.setExecutionListeners(executionListeners);
return serviceTask;
}

how to add 

<extensionElements>
<activiti:taskListener event="create" class="com.xy.z.TaskAssignmentHandler"></activiti:taskListener>
</extensionElements>

This dynamically using java code?

1 Solution

Accepted Solutions
nikmenke
Active Member II

Re: how to add a custom task listener through java code?

Jump to solution

Hi Goutham P N,

this should resolve your issue:

ActivitiListener activitiListener = new ActivitiListener();

activitiListener.setEvent("create");
activitiListener.setImplementation("com.xy.z.TaskAssignmentHandler");
activitiListener.setImplementationType("class");

Now you just have to add it to the service task.

Niklas

View solution in original post

3 Replies
nikmenke
Active Member II

Re: how to add a custom task listener through java code?

Jump to solution

Hi Goutham P N,

this should resolve your issue:

ActivitiListener activitiListener = new ActivitiListener();

activitiListener.setEvent("create");
activitiListener.setImplementation("com.xy.z.TaskAssignmentHandler");
activitiListener.setImplementationType("class");

Now you just have to add it to the service task.

Niklas

goutham_pn
Member II

Re: how to add a custom task listener through java code?

Jump to solution

Thanks Niklas.

How about adding expressions? something like this,

<serviceTask id="st-approve-action" name="Approve Action" activiti:expression="${xyz.Service.send(postDetails)}"></serviceTask>

And

<sequenceFlow id="flow1" sourceRef="gw-accept-reject" targetRef="exclusivegateway1">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${approver1 == false}]]></conditionExpression>
</sequenceFlow>

Thanks,

Goutham

nikmenke
Active Member II

Re: how to add a custom task listener through java code?

Jump to solution

Hi Goutham,

service task:

serviceTask.setImplementation("${xyz.Service.send(postDetails)}");
serviceTask.setImplementationType("expression");

sequence flow:

sequenceFlow.setConditionExpression("${approver1 == false}");