jbpm一直困扰的一个问题
??????? 在使用jbpm的时候创建task 有两种方式,一直是有jbpm给我创建,还有一种是自己根据业务需求手动创建task 而且手动创建时一种非常常见的方式,例如在处理工作流中的汇签问题,
???? 查询资料上提到手动创建task的步骤? 把create-tasks="false" ,在event 事件上边配置要触发的时间类型
以及要触发的class
?
<?xml version="1.0" encoding="GBK"?><process-definition xmlns="urn:jbpm.org:jpdl-3.2" name="helloworld"><swimlane name="initorl"> </swimlane> <start-state name="fillform"> <task name="fillform" swimlane="initorl"></task> <transition to="audit"></transition> </start-state> <task-node name="audit"> <task name="audit"> <assignment actor-id="3"></assignment> </task> <transition to="mgr audit" name="mgr audit"></transition> </task-node> <task-node name="mgr audit" create-tasks="false" ><task name="mgr audit"></task><event type="node-enter"><action ></transition><!--手工添加多人审批 <task name="经理审批"> <assignment actor-id="2"></assignment> </task> <task name="经理审批"> <assignment actor-id="3"></assignment> </task> <task name="经理审批"> <assignment actor-id="4"></assignment> </task> <transition to="mg dic" name="to hr" ></transition> </task-node>--> </task-node> <task-node name="hr mgr"> <task name="hr mgr" swimlane="initorl"> </task> <transition to="end1" ></transition> </task-node> <end-state name="end1"></end-state></process-definition>?
?class 如下
package net.valley.util;import org.jbpm.graph.def.ActionHandler;import org.jbpm.graph.exe.ExecutionContext;import org.jbpm.graph.node.TaskNode;import org.jbpm.taskmgmt.exe.TaskInstance;import org.jbpm.taskmgmt.exe.TaskMgmtInstance;public class CreateTask implements ActionHandler{/** * 根据参与者的个数来创建task的实例个数 * 参与者之间用逗号分隔 * */public void execute(ExecutionContext executionContext) throws Exception {// TODO Auto-generated method stubSystem.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~");TaskNode tn=(TaskNode)executionContext.getNode();String actorid=(String)executionContext.getProcessInstance().getContextInstance().getVariable("nextactorid");TaskMgmtInstance tmi=executionContext.getTaskMgmtInstance();String[] actors=actorid.split(",");for(int i=0;i<actors.length;i++){//一定要加上getToken();TaskInstance ti=tmi.createTaskInstance(tn.getTask("mgr audit"),executionContext.getToken());ti.setActorId(actors[i]);}}}
?
下边代码是让节点向下移动
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%@page import="org.jbpm.JbpmContext"%><%@page import="org.jbpm.JbpmConfiguration"%><%@page import="org.jbpm.graph.exe.ProcessInstance"%><%@page import="org.jbpm.db.GraphSession"%><%@page import="org.jbpm.graph.def.ProcessDefinition"%><%@page import="org.jbpm.taskmgmt.exe.TaskInstance"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <title>xx</title> <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--> </head> <body> <% Long ttid=Long.parseLong(request.getParameter("ttid")); //String tn=request.getParameter("s"); String actid=request.getParameter("sub"); //为了方便期间我把路线指定了,流程定义的时候也只有一个路线 String nextPath="mgr audit"; JbpmContext c=JbpmConfiguration.getInstance().createJbpmContext(); TaskInstance ti=c.loadTaskInstance(ttid); ProcessInstance pi=ti.getProcessInstance(); ti.getProcessInstance().getContextInstance().setVariable("nextactorid",actid); //ti.end("next"); //pi.signal(); //ti.end(nextPath); ti.end(nextPath); c.close(); %> </body></html>
?
现在问题是,ti.end();在调用这个方法的会从audit节点直接跳到hr mgr节点,并没有像预期的那样在mgr audit
节点创建多个task实例,我在CreateTask类中设置断点也没有执行到,
? 请有经验的朋友解释一下,我用的是jbpm3.2.2
?