JBPM4基礎篇04-設計請假流程,JBPM整合到Web Project
阿新 • • 發佈:2019-02-19
這次我們需要在Web專案中整合jbpm。在JSP頁面上實現流程的釋出和刪除。
- 使用Eclipse建立一個Web專案,使用Tomcat6.0作為伺服器。
- 新增依賴庫(Jar包)。這裡我僅將本次測試需要的必須的Jar包加進來。沒有多餘的。(經過嚴格的測試)
此外,start一個流程的時候還要用到juel-impl.jar
也可以直接把/jbpm-4.3/下的jbpm.jar和/jbpm4.3/lib/下的jar包全部複製進去,juel.jar中javax/el中的類與tomcat中的有衝突,把juel.jar中的javax/el刪除即可。 - 將專案需要的一些XML和Properties檔案加進來,放到工程的src目錄下。(/jbpm-4.13/examples/src/)
- 建立一個請假流程檔案leave.jpdl.xml
XML檔案的內容為:
[html] view plaincopyprint?- <?xmlversion="1.0"encoding="UTF-8"?>
- <processname="leave"xmlns="http://jbpm.org/4.3/jpdl">
- <startg="199,100,48,48"name="start1">
- <transitiong="-47,-17"name="to 申請"to="申請"/>
- </start>
- <taskassignee="wxp"
- <transitiong="-71,-17"name="to 經理審批"to="經理審批"/>
- </task>
- <taskassignee="manager"g="182,322,92,52"name="經理審批">
- <transitiong="-83,-17"name="to exclusive1"to="exclusive1"/>
- </task>
- <taskassignee="boss"g="358,471,92,52"name="老闆審批"
- <transitiong="406,571:-47,-17"name="to end1"to="end1"/>
- </task>
- <decisionexpr="#{day > 3 ? 'to 老闆審批' : 'to end1'}"g="208,425,48,48"name="exclusive1">
- <transitiong="-47,-17"name="to end1"to="end1"/>
- <transitiong="405,448:-71,-17"name="to 老闆審批"to="老闆審批"/>
- </decision>
- <endg="211,549,48,48"name="end1"/>
- </process>
<?xml version="1.0" encoding="UTF-8"?> <process name="leave" xmlns="http://jbpm.org/4.3/jpdl"> <start g="199,100,48,48" name="start1"> <transition g="-47,-17" name="to 申請" to="申請"/> </start> <task assignee="wxp" g="178,190,92,52" name="申請"> <transition g="-71,-17" name="to 經理審批" to="經理審批"/> </task> <task assignee="manager" g="182,322,92,52" name="經理審批"> <transition g="-83,-17" name="to exclusive1" to="exclusive1"/> </task> <task assignee="boss" g="358,471,92,52" name="老闆審批"> <transition g="406,571:-47,-17" name="to end1" to="end1"/> </task> <decision expr="#{day > 3 ? 'to 老闆審批' : 'to end1'}" g="208,425,48,48" name="exclusive1"> <transition g="-47,-17" name="to end1" to="end1"/> <transition g="405,448:-71,-17" name="to 老闆審批" to="老闆審批"/> </decision> <end g="211,549,48,48" name="end1"/> </process>
注意:這些配置可以使用外掛在Eclipse中視覺化操作。 - 新建一個index.jsp,建立流程引擎,建立流程服務,釋出流程和刪除流程。
[java] view plaincopyprint?- <%@ page language="java" contentType="text/html; charset=UTF-8"
- pageEncoding="UTF-8"%>
- <%@ page import="java.util.*,org.jbpm.api.*" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=GB18030">
- <title>Insert title here</title>
- </head>
- <body>
- <a href="index.jsp">refresh</a>|
- <a href="index.jsp?action=deploy">deploy</a><br />
- <%
- ProcessEngine processEngine = Configuration.getProcessEngine(); // 建立一個流程引擎
- RepositoryService repositoryService = processEngine.getRepositoryService(); // 建立一個流程服務
- String action = request.getParameter("action"); // 接收指令
- if ("deploy".equals(action)) { // 建立流程
- repositoryService.createDeployment().addResourceFromClasspath("leave.jpdl.xml").deploy();
- } elseif ("remove".equals(action)) { // 刪除流程
- String deploymentId = request.getParameter("deploymentId");
- repositoryService.deleteDeploymentCascade(deploymentId);
- }
- List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery().list(); // 獲取流程列表
- for(ProcessDefinition pd : list) {
- %>
- <%=pd.getId() %>,<%=pd.getName() %>,<%=pd.getVersion() %><a href="index.jsp?action=remove&deploymentId=<%=pd.getDeploymentId() %>">delete</a><br />
- <%
- }
- %>
- </body>
- </html>