流程结合动态web
一、建立环境
跟学习笔记一建立环境差不多。建立Dynamic Web Project.
二、定义流程
建立leave.jpdl.xml文件。
内容如下:
<?xml version="1.0" encoding="UTF-8"?> <process name="leave" xmlns="http://jbpm.org/4.3/jpdl"> <start g="261,11,48,48" name="start1"> <transition g="-42,-18" name="to 申请" to="申请"/> </start> <end g="260,415,48,48" name="end1"/> <task g="238,97,92,52" name="申请" assignee="lingo"> <transition g="-66,-18" name="to 经理审批" to="经理审批"/> </task> <task g="239,194,92,52" name="经理审批" assignee="manager"> <transition g="-68,-18" name="to exclusive1" to="exclusive1"/> </task> <decision g="260,278,48,48" name="exclusive1" expr="#{day>3?'to 老板审批':'to end1'}"> <transition g="442,303:-66,-18" name="to 老板审批" to="老板审批"/> <transition g="-42,-18" name="to end1" to="end1"/> </decision> <task g="396,345,92,52" name="老板审批" assignee="boss"> <transition g="442,438:-42,-18" name="to end1" to="end1"/> </task> </process>
流程图如下:
三、新建index.jsp文件
内容如下:
<%@ 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=UTF-8"> <title>Insert title here</title> </head> <body> web结合流程 <a href="index.jsp?action=deploy" mce_href="index.jsp?action=deploy">deploy</a> <% ProcessEngine processEngine=Configuration.getProcessEngine(); RepositoryService repositoryService = processEngine.getRepositoryService(); String action = request.getParameter("action"); if("deploy".equals(action)){ repositoryService.createDeployment().addResourceFromClasspath("leave.jpdl.xml").deploy(); }else if("remove".equals(action)){ repositoryService.deleteDeploymentCascade(request.getParameter("id")); } List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery().list(); for(ProcessDefinition pd : list){ %> <%=pd.getId() %> , <%=pd.getName() %> , <%=pd.getVersion() %> , <a href="index.jsp?action=remove&id=<%=pd.getDeploymentId() %>">remove</a> <br> <%} %> </body> </html>