最近项目需要工作流,所以就准备采用jBPM4作为工作流引擎,
才开始接触,很多东西都是一步一步摸索出来的,当然了,也搜索了一些文章,下面就是这两天使用jBPM4做的一个请假的例子.
流程比较简单,流程图如下:[img]http://dl.iteye.com/upload/picture/pic/113109/43d132a2-e743-3cef-a5f1-27d1977a219c.jpg[/img]
本来作为才开始学习JBPM的人来说,最好的方法就是先运行起程序,然后学习就要方便很多。
下面是我的servlet文件;
好了,要想查看详细的源码,下载我上传的压缩包吧。
如果你使用的tomcat6, 出现java.lang.LinkageError这个错误的话,那么可以参考[url]http://blog.csdn.net/ol_beta/article/details/5553473[/url]这个文章。
还有不要忘记添加JBPM的jar包哦
才开始接触,很多东西都是一步一步摸索出来的,当然了,也搜索了一些文章,下面就是这两天使用jBPM4做的一个请假的例子.
流程比较简单,流程图如下:[img]http://dl.iteye.com/upload/picture/pic/113109/43d132a2-e743-3cef-a5f1-27d1977a219c.jpg[/img]
本来作为才开始学习JBPM的人来说,最好的方法就是先运行起程序,然后学习就要方便很多。
下面是我的servlet文件;
package com.vito.jbpm.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.jbpm.api.Configuration;
import org.jbpm.api.Execution;
import org.jbpm.api.ExecutionService;
import org.jbpm.api.ProcessDefinition;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.ProcessInstance;
import org.jbpm.api.RepositoryService;
import org.jbpm.api.TaskService;
import org.jbpm.api.model.ActivityCoordinates;
import org.jbpm.api.task.Task;
/**
* 请假流程Servlet
* @author 周文滔 <zhouwentao16@gmail.com>
* @time 2012-5-27 下午05:39:32
*/
public class LeaveServlet extends HttpServlet {
private ProcessEngine processEngine = null;
private RepositoryService repositoryService = null;
private ExecutionService executionService = null;
private ProcessInstance processInstance = null;
private TaskService taskService = null;
public LeaveServlet() {
super();
}
public void init(ServletConfig config) throws ServletException {
super.init(config);
// 获取流程引擎
processEngine = new Configuration().buildProcessEngine();
repositoryService = processEngine.getRepositoryService();
executionService = processEngine.getExecutionService();
taskService = processEngine.getTaskService();
}
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
process(request, response);
}
protected void process(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String action = request.getParameter("action");
HttpSession session = request.getSession();
if (action.equals("leave")) {
request.getRequestDispatcher("").forward(request, response);
} else if (action.equals("list")) {
String username = (String) session.getAttribute("username");
List<ProcessDefinition> pdList = repositoryService
.createProcessDefinitionQuery().list();
List<ProcessInstance> piList = executionService
.createProcessInstanceQuery().list();
List<Task> taskList = taskService.findPersonalTasks(username);
session.setAttribute("pdList", pdList);
session.setAttribute("piList", piList);
session.setAttribute("taskList", taskList);
request.getRequestDispatcher("list.jsp").forward(request, response);
}else if (action.equals("start")) {
Map map = new HashMap();
map.put("user",session.getAttribute("username"));
executionService.startProcessInstanceById(request.getParameter("id"),map);
request.getRequestDispatcher("leave?action=list").forward(request, response);
}else if (action.equals("submit")) {
String taskId = request.getParameter("taskId");
int day = Integer.parseInt(request.getParameter("day"));
String reason = request.getParameter("reason");
reason = new String(reason.getBytes("ISO-8859-1"),"UTF-8");
Map map = new HashMap();
map.put("days", day);
map.put("reason", reason);
taskService.completeTask(taskId, "to_teacher",map);
request.getRequestDispatcher("leave?action=list").forward(request, response);
}else if (action.equals("view")) {
String id = request.getParameter("id");
processInstance = executionService.findProcessInstanceById(id);
Set<String> activityNames = processInstance.findActiveActivityNames();
ActivityCoordinates ac = repositoryService.getActivityCoordinates(processInstance.getProcessDefinitionId(),activityNames.iterator().next());
request.setAttribute("ac", ac);
request.getRequestDispatcher("view.jsp").forward(request, response);
}else if (action.equals("deploy")) {
repositoryService.createDeployment().addResourceFromClasspath("leave.jpdl.xml").deploy();
}else if(action.equals("sh")){
String taskId = request.getParameter("taskId");
String result = request.getParameter("result");
result = new String(result.getBytes("ISO-8859-1"), "UTF-8");
System.out.println(result);
taskService.completeTask(taskId, result);
request.getRequestDispatcher("leave?action=list").forward(request, response);
}
}
}
好了,要想查看详细的源码,下载我上传的压缩包吧。
如果你使用的tomcat6, 出现java.lang.LinkageError这个错误的话,那么可以参考[url]http://blog.csdn.net/ol_beta/article/details/5553473[/url]这个文章。
还有不要忘记添加JBPM的jar包哦