Ok, now that Gavin gave a nice combination of @StartTask and pages.xml, I 
wonder if something similar could be done using the value returned by 
@CreateProcess, somehow also forcing @StartTask to be triggered?

Now, how to explain this... In the Todo example we've got:
@CreateProcess(definition = "todo")
  | public void createTodo() { 
  |     // nothing here in fact
  | }
and
<process-definition name="todo">
  |     :
  |     <task-node name="todo">
  |         <task name="todo" description="#{todoList.description}">
  |         <assignment actor-id="#{actor.id}"/>
  |     </task>
  |     :
  | </process-definition>
Above, when createTodo() completes successfully then @CreateProcess somehow 
tells jBPM that the process is started. Eventually the <task-node> is reached 
at which point jBPM will create the org.jbpm.taskmgmt.exe.TaskInstance and 
assign it to the current actor. Next, the task could be started using, for 
example, Gavin's TaskSelector#selectTask. 

Above, createTodo() does not return a value, so the actor stays at the current 
page. In my example I do in fact return a value, which gives the actor my page 
on which I check if the task has been started. To find the single task that I 
expect, I use something like:
@Name("taskFinder")
  | public class TaskFinder {
  |     @Logger Log log;
  |     @In ProcessInstance processInstance;
  | 
  |     /**
  |      * Convenience method to get the single task from the current process
  |      * instance.
  |      * <p>
  |      * Assumes the process instance holds exactly one task; returns
  |      * <code>null</code> if none or multiple tasks are found.
  |      * 
  |      * @return org.jbpm.taskmgmt.exe.TaskInstance, just like returned by
  |      *         [EMAIL PROTECTED] org.jboss.seam.core.TaskInstanceList}, or 
  |      *         <code>null</code> when none or multiple tasks are found.
  |      */
  |     @SuppressWarnings("unchecked")
  |     public TaskInstance getSingleTaskInstance() {
  |         Collection<TaskInstance> taskInstances =
  |             (Collection<TaskInstance>) processInstance.getTaskMgmtInstance()
  |             .getTaskInstances();
  | 
  |         if (taskInstances.size() != 1) {
  |             log.error("Expected single task, found #0", 
taskInstances.size());
  |             return null;
  |         }
  |         return (TaskInstance)taskInstances.iterator().next();
  |     }
  | }

and

<c:choose>
  |     <c:when test="#{taskInstance == null}">
  |         <p>This task has not yet been started.</p>
  |         <p><s:link action="#{taskSelector.startTask}"
  |             taskInstance="#{taskFinder.singleTaskInstance}"
  |             value="Start now" />.</p>
  |     </c:when>
  |     <c:otherwise>
  |     :

So, though all of this happens AFTER createTodo() completes, for this specific 
process I know that a single task is created (almost) immediately. I actually 
even know the name of that task. So I can assume only a single task will be 
found.

Though the above works for me (well, I guess in some cases I actually would 
like it to start automatically when needed...), I wonder if this could somehow 
be implemented without my TaskFinder, for example using pages.xml?

(and errr, yes, in the Todo-list example starting the task would in fact also 
end it, but just suppose the @EndTask is set on another method so we could show 
some Todo-task page...)


View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4030275#4030275

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4030275
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to