3 Replies Latest reply on Jan 11, 2007 9:27 AM by Norman Richards

    How to use org.jboss.seam.core.TaskInstance?

    Alexei none Apprentice

      I created a simple task manager which allows to start, end tasks and retrieve task's variables

      import org.jboss.seam.core.TaskInstance;

      @Stateful
      @Name("taskManager")
      @Scope(ScopeType.CONVERSATION)
      public class TaskManagerImpl implements TaskManager {

      @In(required=false)
      private Long taskId;
      @DataModel
      private List transitions;
      @DataModelSelection("transitions")
      private Transition selectedTransition;
      @DataModel
      private List taskFormParameters;
      @DataModelSelection("taskFormParameters")
      private TaskFormParameter taskFormParameter;

      @BeginTask
      public String startTask() {

      org.jbpm.taskmgmt.exe.TaskInstance taskInstance = TaskInstance.instance();
      if(taskInstance != null) {

      this.transitions = taskInstance.getAvailableTransitions();
      this.comments = taskInstance.getComments();

      taskFormParameters = new ArrayList();
      TaskController taskController = taskInstance.getTask().getTaskController();
      if (taskController!=null) {
      for(Object va : taskController.getVariableAccesses()) {

      VariableAccess variableAccess = (VariableAccess) va;
      String mappedName = variableAccess.getMappedName();
      String value = (String)taskInstance.getVariable(mappedName);
      TaskFormParameter tfp = new TaskFormParameter(variableAccess, value);
      System.out.println("reading [" + tfp.getLabel() + "]=" + tfp.getValue() + " readable " + tfp.isReadable() + " writable " + tfp.isWritable());
      taskFormParameters.add(tfp);
      }
      }

      }
      return "/task.xhtml";

      }

      @EndTask
      public String endTask() {

      org.jbpm.taskmgmt.exe.TaskInstance taskInstance = TaskInstance.instance();
      BusinessProcess.instance().transition(selectedTransition.getName());

      for(TaskFormParameter tfp : this.taskFormParameters){
      if (tfp.isWritable()) {

      System.out.println("isOpen " + taskInstance.isOpen());
      System.out.println("submitting [" + tfp.getLabel() + "]=" + tfp.getValue() + " readable " + tfp.isReadable() + " writable " + tfp.isWritable());
      taskInstance.setVariable(tfp.getLabel(), tfp.getValue());
      System.out.println("test " + taskInstance.getVariable(tfp.getLabel()));

      } else {

      System.out.println("ignoring unwritable [" + tfp.getLabel() + "]");

      }

      }

      return "/available.xhtml";

      }

      @End
      public String cancelTask() {

      return "/available.xhtml";

      }


      @Remove @Destroy
      public void remove() {

      }

      }

      then i defined a simple workflow


      <?xml version="1.0"?>

      <process-definition name="sampleflow">
      <start-state name="start">
      < task name="start">
      <assignment pooled-actors="debuggers"/>
      </ task>

      </start-state>

      <task-node name="sample">
      < task name="sample" description="sample description">
      <assignment pooled-actors="debuggers"/>

      <variable name="readableVar" mapped-name="readableVar" access="read,write"/>
      <variable name="writableVar" mapped-name="writableVar" access="read,write"/>

      </ task>


      </task-node>
      <task-node name="task1">
      < task name="another sample task" description="sample description">
      <assignment pooled-actors="debuggers"/>

      <variable name="readableVar" access="read" mapped-name="readableVar"/>
      <variable name="writableVar" access="read" mapped-name="writableVar"/>

      </ task>

      </task-node>

      <end-state name="end"/>

      </process-definition>

      The trouble is that not null variables in task named sample, become null in task named another sample task