cancel
Showing results for 
Search instead for 
Did you mean: 

CDI: Howto 'pause' an user task with flush of variables

chris_joelly
Champ in-the-making
Champ in-the-making
Hello,

on a JSF mask i use

<f:event type="preRenderView" listener="#{businessProcess.startTask(taskId, true)}" />
to start the user task and

<h:commandButton action="#{businessProcess.completeTask(true)}" value="Complete" />
to complete the user task.

I now want to add a button where the user is able to "pause" the user task and flush and store all process variables associated with the task. And if he come back later to this task he might add additional content and complete or pause the task again.

Is there something like …pauseTask()?

Thanks,
Chris
4 REPLIES 4

rogerofyan
Champ in-the-making
Champ in-the-making
I think a user task is paused by default, since task is of 'block' element, which will block the process execution until you implicity push it ahead.
You can store variables with taskService after you starting a task, and retrieve it back anytime later.

chris_joelly
Champ in-the-making
Champ in-the-making
yes, storing the variables using the TaskService is possible, but as the businessProcess.startTask and businessProcess.completeTask create a scope and association of the execution to the scope (i think Conversation scope) this scope needs to be closed and the association removed as well.

meyerd
Champ on-the-rise
Champ on-the-rise
Hi Chris,

The following should work:


public class Controller {

@Inject
private BusinessProcessAssociationManager associationManager;

@Inject
private TaskService taskService;

public void pauseUserTask() {
  Task task = associationManager.getTask();
  if(task == null) {
   throw new RuntimeException("Not working on a task");
  }
  // flush the variables
  Map<String, Object> changedVariables = associationManager.getBeanStore().getAllAndClear();
  if(changedVariables.size()>0) {
   taskService.setVariables(task.getId(), changedVariables);
  }
  // remove the association with the current task.
  associationManager.disAssociate();
}

}

chris_joelly
Champ in-the-making
Champ in-the-making
Hi Daniel,

thanks for the hint with the associationManager. I already tried to extend the BusinessProcess bean but did not think of using the BusinessProcessAssociationManager.

When i think of the conversation and association:

Is it safe to end an active conversion as well when i pause/suspend an user task?
And when the user does not leave the form and continue his work (within the session timeout of course),
how can i recover from it? I think there should be some kind of resume as well after the pause/suspend?
Or is it better to redirect the user to the task list from which he can work on another task or restart the
"paused" task which then starts a new conversation and association cleanly?

Thanks, Chris

btw: BusinessProcess.startTask(String taskId, boolean beginConversation) ignores the argument beginConversation.