TaskFormData is null inside complete taskListener
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2013 11:11 PM
I have a user task for which I am invoking a task listener when the task completes:
The code which is being invoked by the listener is:
[java]
public class FormCollectionBuilder {
public void addForm(DelegateExecution execution) throws Exception {
final String taskId = execution.getCurrentActivityId();
final String taskFormCollId = taskId + "FormCollection";
@SuppressWarnings("unchecked")
List<List<FormProperty>> forms =
(List<List<FormProperty>>) execution.getVariable(taskFormCollId);
if (forms == null) {
forms = new ArrayList<List<FormProperty>>();
execution.setVariable(taskFormCollId, forms);
}
TaskFormData formData = execution.getEngineServices().getFormService().getTaskFormData(taskId);
final List<FormProperty> formProps = formData.getFormProperties();
forms.add(formProps);
}
}
[/java]
The issue I am having is that the call to getTaskFormData is returning null. Looking in my debugger at runtime, the task ID is "getDoorInfo", which is the correct one, so I can't figure out why this is returning null. Any idea what I'm doing wrong?
<userTask id="getDoorInfo" name="Get door info" activiti:exclusive="false"> <extensionElements> <activiti:formProperty id="doorColor" name="Door color" variable="doorColor" readable="true" type="string" required="true" /> <activiti:taskListener event="complete" expression="${formCollectionBuilder.addForm(execution)}" /> </extensionElements> <potentialOwner> <resourceAssignmentExpression> <formalExpression>management</formalExpression> </resourceAssignmentExpression> </potentialOwner> <multiInstanceLoopCharacteristics isSequential="true"> <loopCardinality>${numDoors}</loopCardinality> </multiInstanceLoopCharacteristics> </userTask>
The code which is being invoked by the listener is:
[java]
public class FormCollectionBuilder {
public void addForm(DelegateExecution execution) throws Exception {
final String taskId = execution.getCurrentActivityId();
final String taskFormCollId = taskId + "FormCollection";
@SuppressWarnings("unchecked")
List<List<FormProperty>> forms =
(List<List<FormProperty>>) execution.getVariable(taskFormCollId);
if (forms == null) {
forms = new ArrayList<List<FormProperty>>();
execution.setVariable(taskFormCollId, forms);
}
TaskFormData formData = execution.getEngineServices().getFormService().getTaskFormData(taskId);
final List<FormProperty> formProps = formData.getFormProperties();
forms.add(formProps);
}
}
[/java]
The issue I am having is that the call to getTaskFormData is returning null. Looking in my debugger at runtime, the task ID is "getDoorInfo", which is the correct one, so I can't figure out why this is returning null. Any idea what I'm doing wrong?
Labels:
- Labels:
-
Archive
2 REPLIES 2

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2013 06:17 AM
This is not the correct task id, you are using the task definition key. For a task listener it would be better to use a DelegateTask as input parameter and get the task id from there. You can use the following expression for that:
${formCollectionBuilder.addForm(task)}
Best regards,
${formCollectionBuilder.addForm(task)}
Best regards,
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2013 10:39 PM
Yep, worked like a charm. Thanks, you rock!

