- 浏览: 448913 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
g_man1990:
update config 不成功啊
build-helper-maven-plugin 配置多 source resource 文件 -
netwelfare:
文章很详细,就是太长了,读起来有点困难,倒不如写精练点,像这篇 ...
Java 基本类型 -
huyuancai1010:
function commitForm() {
var ...
加时间戳或者随机数去除js缓存 -
Smile__:
不过这个东西以前还真没研究过 。
hibernate.jdbc.fetch_size 和 hibernate.jdbc.batch_size -
Smile__:
想不到你也是北大青鸟的 。哈
hibernate.jdbc.fetch_size 和 hibernate.jdbc.batch_size
1.新建一个动态的web项目
2.在lib目录下加入以下jar包(由于用到fileupload的上传,所以还要加入fileupload的依赖库)
引用
*JBPM4_HOME/jbpm.jar
*JBPM4_HOME/lib/*.jar
*jakarta-taglibs-standard-1.1.2_HOME/lib/jstl.jar
*jakarta-taglibs-standard-1.1.2_HOME/lib/standard.jar
*commons-fileupload-1.2.1_HOME/lib/commons-fileupload-1.2.1.jar
3.绘制流程图(在resources目录下建立一个leave.jpdl.xml文件)
<?xml version="1.0" encoding="UTF-8"?> <process name="leave" xmlns="http://jbpm.org/4.0/jpdl"> <start g="201,14,48,48" name="开始"> <transition g="-42,-10" name="请假" to="填写请假单"/> </start> <task assignee="Kayzhan" g="178,87,92,52" name="填写请假单"> <transition g="-97,2" name="判断是不是经理" to="是不是经理"/> </task> <decision expr="#{manager}" g="204,158,48,48" name="是不是经理"> <transition g="-23,-11" name="否" to="经理审核"/> <transition g="14,-11" name="是" to="老板审批"/> </decision> <task assignee="Lingo" g="103,252,92,52" name="经理审核"> <transition g="150,450:10,-21" name="经理批准" to="结束"/> <transition g="-22,-22" name="请假天数>3" to="老板审批"/> <transition g="-61,-1" name="经理不批准" to="终止"/> <transition g="149,114:-55,82" name="经理驳回" to="填写请假单"/> </task> <task assignee="ForgetDavi" g="278,251,92,52" name="老板审批"> <transition g="326,450:-58,-24" name="老板批准" to="结束"/> <transition g="7,0" name="老板不批准" to="终止"/> <transition g="323,114:13,61" name="老板驳回" to="填写请假单"/> </task> <end g="219,429,48,48" name="结束" state="confirm"/> <end g="220,360,48,48" name="终止" state="dissent"/> </process>
4.编写流程发布及控制的类
- /**
- * Servlet implementation class LeaveServlet
- */
- public class LeaveServlet extends HttpServlet {
- private static final long serialVersionUID = 1L;
- private ProcessEngine processEngine = null;
- private RepositoryService repositoryService = null;
- private ExecutionService executionService = null;
- private ProcessInstance processInstance = null;
- private TaskService taskService = null;
- private Task task = null;
- private Execution execution = null;
- private String url = null;
- private List list = null;
- private List<Task> taskList = null;
- /* 初始化ProcessEngine. */
- public void init(ServletConfig config) throws ServletException {
- super.init(config);
- // 获取流程引擎
- processEngine = new Configuration().buildProcessEngine();
- repositoryService = processEngine.getRepositoryService();
- executionService = processEngine.getExecutionService();
- taskService = processEngine.getTaskService();
- }
- protected void doGet(HttpServletRequest request,
- HttpServletResponse response) throws ServletException, IOException {
- process(request, response);
- }
- protected void doPost(HttpServletRequest request,
- HttpServletResponse response) throws ServletException, IOException {
- process(request, response);
- }
- protected void process(HttpServletRequest request,
- HttpServletResponse response) throws ServletException, IOException {
- String zzg = request.getParameter("zzg");
- if (zzg.equals("deploy")) {
- try {
- deploy(request, response);
- } catch (Exception e) {
- e.printStackTrace();
- }
- list = getLatestProcessDefinition(request, response);
- request.setAttribute("process", list);
- request.getRequestDispatcher("/index.jsp").forward(request,
- response);
- } else if (zzg.equals("leave")) {
- url = leave(request, response);
- request.getRequestDispatcher(url).forward(request, response);
- } else if (zzg.equals("query")) {
- list = getProcessInstanceById(request, response);
- request.setAttribute("pi", list);
- request.getRequestDispatcher("/index.jsp").forward(request,
- response);
- } else if (zzg.equals("apply")) {
- apply(request, response);
- list = getProcessInstanceById(request, response);
- request.setAttribute("pi", list);
- request.getRequestDispatcher("/index.jsp").forward(request,
- response);
- } else if (zzg.equals("getTask")) {
- list = getTask(request, response);
- request.setAttribute("taskList", list);
- request.getRequestDispatcher("/check.jsp").forward(request,
- response);
- } else if (zzg.equals("view")) {
- Map<String, Object> map = view(request, response);
- request.setAttribute("map", map);
- request.getRequestDispatcher("/view.jsp")
- .forward(request, response);
- } else if (zzg.equals("confirm")) {
- confirm(request, response);
- list = getTask(request, response);
- request.setAttribute("taskList", list);
- request.getRequestDispatcher("/check.jsp").forward(request,
- response);
- } else if (zzg.equals("dissent")) {
- dissent(request, response);
- list = getTask(request, response);
- request.setAttribute("taskList", list);
- request.getRequestDispatcher("/check.jsp").forward(request,
- response);
- }
- /*
- * try { Class clz = this.getClass(); Method method =
- * clz.getDeclaredMethod(action, HttpServletRequest.class,
- * HttpServletResponse.class); method.invoke(this, request, response); }
- * catch (Exception ex) { ex.printStackTrace(); }
- */
- }
- protected void deploy(HttpServletRequest request,
- HttpServletResponse response) throws Exception, IOException {
- String temp = getServletContext().getRealPath("/temp");
- String upload = getServletContext().getRealPath("/upload");
- DiskFileUpload diskFileUpload = new DiskFileUpload();
- diskFileUpload.setFileSizeMax(1 * 1024 * 1024);
- diskFileUpload.setSizeThreshold(4096);
- diskFileUpload.setRepositoryPath(temp);
- List fileItems = diskFileUpload.parseRequest(request);
- Iterator iter = fileItems.iterator();
- if (iter.hasNext()) {
- FileItem item = (FileItem) iter.next();
- if (!item.isFormField()) {
- String name = item.getName();
- long size = item.getSize();
- System.out.println("name: " + name + "&size:" + size);
- if (name != null && !name.equals("") && size > 0) {
- // Deploying a process部署流程
- repositoryService.createDeployment()
- .addResourcesFromZipInputStream(
- new ZipInputStream(item.getInputStream()))
- .deploy();
- }
- }
- }
- }
- protected String leave(HttpServletRequest request,
- HttpServletResponse response) throws ServletException, IOException {
- // 根据流程定义的KEY值启动一个新的流程实例
- processInstance = executionService.startProcessInstanceByKey("leave");
- //判断流程定义的活动是否是“填写请假单”的活动
- if (processInstance.isActive("填写请假单")) {
- url = "/apply.jsp";
- }
- return url;
- }
- protected Map<String, Object> apply(HttpServletRequest request,
- HttpServletResponse response) throws ServletException, IOException {
- Map<String, Object> variables = new HashMap<String, Object>();
- String name = request.getParameter("applyName");
- String time = request.getParameter("applyTime");
- String leaveDay = request.getParameter("leaveDay");
- String content = request.getParameter("content");
- String position = request.getParameter("position");
- variables.put("name", name);
- variables.put("time", time);
- variables.put("leaveDay", leaveDay);
- variables.put("content", content);
- variables.put("position", position);
- if (position.trim().equals("经理")) {
- //"manager"变量名与leave.jpdl.xml中decision里面的变量一致,同时设置的值也要保持一致
- variables.put("manager", "是");
- } else {
- variables.put("manager", "否");
- }
- //获取任务列表,因为我们在填写请假单的时候是分配给“zzg”的,见leave.jpdl.xml
- taskList = taskService.findPersonalTasks("zzg");
- //根据任务列表获取任务
- task = taskList.get(0);
- //把设置好的变量放到任务服务里面并根据任务ID结束任务
- taskService.setVariables(task.getId(), variables);
- taskService.completeTask(task.getId());
- //判断任务活动是否到达老板审批活动
- // execution = executionService.findExecutionById(task.getExecutionId());
- // System.out.println("isActive: "
- // + execution.getProcessInstance().isActive("老板审批"));
- return variables;
- }
- /**
- * 获取任务列表
- *
- * @param request
- * @param response
- * @return
- * @throws ServletException
- * @throws IOException
- */
- protected List<Task> getTask(HttpServletRequest request,
- HttpServletResponse response) throws ServletException, IOException {
- String name = request.getParameter("name");
- taskList = taskService.findPersonalTasks(name);
- return taskList;
- }
- /**
- * 查看任务
- *
- * @param request
- * @param response
- * @return
- * @throws ServletException
- * @throws IOException
- */
- protected Map<String, Object> view(HttpServletRequest request,
- HttpServletResponse response) throws ServletException, IOException {
- String taskId = request.getParameter("id");
- Set<String> set = taskService.getVariableNames(taskId);
- Map<String, Object> map = taskService.getVariables(taskId, set);
- return map;
- }
- protected void confirm(HttpServletRequest request,
- HttpServletResponse response) throws ServletException, IOException {
- String taskId = request.getParameter("id");
- task = taskService.getTask(taskId);
- execution = executionService.findExecutionById(task.getExecutionId());
- if (execution.getProcessInstance().isActive("老板审批")) {
- taskService.completeTask(taskId, "老板批准");
- } else if (execution.getProcessInstance().isActive("经理审核")) {
- String variable = (String) taskService.getVariable(taskId,
- "leaveDay");
- if (Integer.valueOf(variable) > 3) {
- taskService.completeTask(taskId, "请假天数>3");
- } else {
- taskService.completeTask(taskId, "经理批准");
- }
- }
- }
- protected void dissent(HttpServletRequest request,
- HttpServletResponse response) throws ServletException, IOException {
- String taskId = request.getParameter("id");
- task = taskService.getTask(taskId);
- execution = executionService.findExecutionById(task.getExecutionId());
- if (execution.getProcessInstance().isActive("老板审批")) {
- taskService.completeTask(taskId, "老板不批准");
- } else if (execution.getProcessInstance().isActive("经理审核")) {
- taskService.completeTask(taskId, "经理不批准");
- }
- }
- /**
- * 获取最新版本的流程定义
- * @param request
- * @param response
- * @return
- * @throws ServletException
- * @throws IOException
- */
- protected List<ProcessDefinition> getLatestProcessDefinition(
- HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- List<ProcessDefinition> processDefinitions = repositoryService
- .createProcessDefinitionQuery().orderAsc(
- ProcessDefinitionQuery.PROPERTY_NAME).list();
- Map<String, ProcessDefinition> map = new LinkedHashMap<String, ProcessDefinition>();
- for (ProcessDefinition pd : processDefinitions) {
- String key = pd.getKey();
- ProcessDefinition definition = map.get(key);
- if ((definition == null)
- || (definition.getVersion() < pd.getVersion())) {
- map.put(key, pd);
- }
- }
- return new ArrayList(map.values());
- }
- /**
- * 根据流程定义ID获取流程实例
- * @param request
- * @param response
- * @return
- * @throws ServletException
- * @throws IOException
- */
- protected List<ProcessInstance> getProcessInstanceById(
- HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- String pdId = request.getParameter("id");
- return executionService.createProcessInstanceQuery()
- .processDefinitionId(pdId).list();
- }
- }
5.在webapp目录下创建一个index.jsp页面,用来发布流程、显示流程定义及流程实例
- <%@page contentType="text/html;charset=UTF-8" %>
- <%@page import="org.jbpm.api.*" %>
- <%@page import="java.util.*" %>
- <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
- <html>
- <head>
- <title>jBPM4流程发布</title>
- </head>
- <body>
- <form action="leave?zzg=deploy" method="POST" enctype="multipart/form-data">
- <input type="file" name="upload">
- <input type="submit" value="发布">
- </form>
- <ul>
- <li><a href="leave?zzg=leave">请假</a></li>
- <li><a href="leave?zzg=getTask&name=Lingo" target="_blank">经理的任务列表</a></li>
- <li><a href="leave?zzg=getTask&name=ForgetDavi" target="_blank">老板的任务列表</a></li>
- </ul>
- <table width=480 border=1>
- <tr><td colspan="5">流程定义</td></tr>
- <tr>
- <td>ID</td>
- <td>Key</td>
- <td>名称</td>
- <td>版本</td>
- <td>操作</td>
- </tr>
- <c:forEach var="process" items="${process}">
- <tr>
- <td>${process.id}</td>
- <td>${process.key}</td>
- <td>${process.name}</td>
- <td>${process.version}</td>
- <td><a href="leave?zzg=query&id=${process.id }">查看</a></td>
- </tr>
- </c:forEach>
- </table>
- <br>
- <br>
- <br>
- <table width=480 border=1>
- <tr><td colspan="5">流程实例</td></tr>
- <tr>
- <td>ID</td>
- <td>Key</td>
- <td>状态</td>
- </tr>
- <c:forEach var="pi" items="${pi}">
- <tr>
- <td>${pi.id}</td>
- <td>${pi.key}</td>
- <td>${pi.state}</td>
- </tr>
- </c:forEach>
- </table>
- </body>
- </html>
6.在webapp目录创建一个apply.jsp页面,用来填写请假单
<%@page contentType="text/html;charset=UTF-8" %> <html> <head> <title>填写申请单</title> </head> <body> <form action="leave?zzg=apply" method="POST"> <table width="300" border=1> <tr> <td><label>申请人</label></td> <td><input type="text" value="zzg" name="applyName"></td> </tr> <tr> <td><label>职位</label></td> <td><input type="text" value="经理" name="position"></td> </tr> <tr> <td><label>申请时间</label></td> <td><input type="text" value="2009-03-09" name="applyTime"></td> </tr> <tr> <td><label>请假天数</label></td> <td><input type="text" value="3" name="leaveDay"></td> </tr> <tr> <td><label>请假原因</label></td> <td><textarea name="content" rows=3 cols=200>病假</textarea></td> </tr> <tr> <td><input type="submit" value="申请"></td> <td><input type="reset" value="取消"></td> </tr> </table> </form> </body> </html>
7.在webapp目录下创建一个check.jsp文件,用来显示任务列表并添加三个操作
- <%@page contentType="text/html;charset=UTF-8" %>
- <%@page import="org.jbpm.api.*" %>
- <%@page import="java.util.*" %>
- <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
- <html>
- <head>
- <title>请假审批</title>
- </head>
- <body>
- <table width=600 border=1>
- <tr><td colspan="8">任务列表</td></tr>
- <tr>
- <td>ID</td>
- <td>名称</td>
- <td>分配人</td>
- <td>创建时间</td>
- <td>持续时间</td>
- <td>优先级</td>
- <td>描述</td>
- <td>操作</td>
- </tr>
- <c:forEach var="task" items="${taskList}">
- <tr>
- <td>${task.id}</td>
- <td>${task.name}</td>
- <td>${task.assignee}</td>
- <td>${task.createTime}</td>
- <td>${task.duedate}</td>
- <td>${task.priority}</td>
- <td>${task.description}</td>
- <td>
- <a href="leave?zzg=view&id=${task.id }" target="_blank">审核</a>
- <a href="leave?zzg=confirm&id=${task.id }&name=${task.assignee}">批准</a>
- <a href="leave?zzg=dissent&id=${task.id }&name=${task.assignee}">不批准</a>
- </td>
- </tr>
- </c:forEach>
- </table>
- </body>
- </html>
8.在webapp目录下创建一个view.jsp文件,用来显示请假内容
- <%@page contentType="text/html;charset=UTF-8" %>
- <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
- <html>
- <head>
- <title>审核</title>
- </head>
- <body>
- <table width="300" border=1>
- <tr>
- <td><label>申请人</label></td>
- <td>${map.name }</td>
- </tr>
- <tr>
- <td><label>职位</label></td>
- <td>${map.position }</td>
- </tr>
- <tr>
- <td><label>申请时间</label></td>
- <td>${map.time }</td>
- </tr>
- <tr>
- <td><label>请假天数</label></td>
- <td>${map.leaveDay }</td>
- </tr>
- <tr>
- <td><label>请假内容</label></td>
- <td>${map.content }</td>
- </tr>
- </table>
- </body>
- </html>
9.修改web.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
- <display-name>LeaveJbpm</display-name>
- <servlet>
- <description>
- </description>
- <display-name>LeaveServlet</display-name>
- <servlet-name>LeaveServlet</servlet-name>
- <servlet-class>
- zzg.LeaveServlet</servlet-class>
- </servlet>
- <servlet-mapping>
- <servlet-name>LeaveServlet</servlet-name>
- <url-pattern>/leave</url-pattern>
- </servlet-mapping>
- <welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
- </web-app>
10.把leave.jpdl.xml文件压缩成zip文件发布即可。
评论
3 楼
Ellen_wen
2011-02-11
cfg
2 楼
haiyangyiba
2011-01-19
LZ要是能把可以运行的例子给以附件的形式传上来最好了。
1 楼
dlhzt
2010-07-23
例子既然是从建立java动态web工程说起,那就应该详细点都说到。
目前这个例子按照你的顺序来,根本跑不起来,
最起码1、jbpm.cfg.xml这块怎么配置。否则报错找不到这个文件
2 “把leave.jpdl.xml文件压缩成zip文件发布即可”这句话也太含糊了,
本来以为是个好的起步例子!
目前这个例子按照你的顺序来,根本跑不起来,
最起码1、jbpm.cfg.xml这块怎么配置。否则报错找不到这个文件
2 “把leave.jpdl.xml文件压缩成zip文件发布即可”这句话也太含糊了,
本来以为是个好的起步例子!
相关推荐
**jBPM4完整例子详解** jBPM4是一个企业级的工作流管理系统,它提供了强大的业务流程管理和工作流实现能力。这个"jBPM4完整例子"是一个基于SSH(Struts2、Spring、Hibernate)框架集成jBPM4.4的请假流程应用,非常...
在"风中叶老师讲的JBPM4与Spring整合例子代码"中,我们可以了解到如何将这两个强大的工具结合在一起,以实现企业级工作流的自动化处理。下面将深入探讨这一整合的关键知识点: 1. **Spring配置JBPM4**:首先,我们...
**JBPM4.4入门详解** JBPM,全称Java Business Process Management...通过实践这个简单的jsp+servlet例子,你将能够初步掌握如何在实际应用中使用JBPM。在学习过程中,不断探索和实践,逐步提升你的业务流程管理能力。
【jbpm4入门例子——在Tomcat6.0下的实现】 jbPM4,全称Java Business Process Management,是一个开源的工作流管理系统,它提供了一整套工具和服务,用于管理业务流程。jbPM4的设计目标是让业务流程的建模、部署、...
【jbpm4的员工请假例子原码】是一个基于jbpm4流程引擎的示例项目,展示了如何在企业中实现一个简单的员工请假流程。这个Web项目是完全开源的,可以通过Eclipse这样的集成开发环境来打开和运行,对于学习和理解jbpm4...
【JBPM例子】是关于Java Business Process Management System (JBPM) 的一系列示例代码,用于展示如何在实际项目中使用这个工作流引擎。JBPM是一个开源的企业级平台,主要用于管理和执行业务流程。它提供了全面的...
【jbpm4web请假例子】是一个基于JBPM4工作流引擎的示例应用,它演示了如何在Eclipse环境中开发和部署一个简单的请假流程。这个例子可以帮助开发者理解工作流管理系统的基本概念,以及如何将它们集成到实际的Web应用...
【JBPM web(SSH+JBPM)例子】是一个基于Java技术栈实现的工作流管理系统示例,其中SSH代表Spring、Struts和Hibernate这三个流行的Java企业级开发框架的组合,而JBPM则是Business Process Management(业务流程管理...
这个"我自己写的jbpm小例子"旨在帮助用户快速理解jbpm的核心概念和基本操作,以轻松上手这个强大的工具。 首先,让我们深入理解jbpm的主要组件和功能: 1. **流程定义**:jbpm使用BPMN 2.0(Business Process ...
4. **流程建模**:jbpm5支持使用BPMN2.0语言进行流程建模,这是一种图形化的建模语言,包含各种元素如开始事件、结束事件、任务、网关等。你将了解如何使用Eclipse的jbpm Workbench或jBPM Designer工具来创建和编辑...
**jbpm4测试例子(项目中含hsqldb数据库)** jbpm4 是一个开源的工作流管理系统,它提供了业务流程管理(BPM)和工作流服务。jbpm4的测试例子是一个很好的学习资源,帮助开发者了解如何在实际项目中集成和使用jbpm4。...
这个“请假例子”旨在帮助初学者快速理解JBPM4的基本概念和操作。 1. **流程定义**:在JBPM4中,业务流程是通过BPML(Business Process Modeling Language)或者BPMN(Business Process Model and Notation)来定义...
这是本人学习jbpm以来看过的写的最有条理的一个例子,基于现在网上jbpm的例子比较的少,所以上传上来和大家一起分享
4. **任务服务**: JBPM提供了任务服务,使得用户可以参与到流程中,完成特定的任务。任务服务包括任务的分配、领取、完成、查询等功能,且与用户系统集成方便,能提供良好的用户体验。 5. **监控和报表**: JBPM5.4...
这是一个完整的jbpm借款例子 调试环境tomcat6 +jbpm 3.2 + jdk5 tomcat6 lib里边要有 commons-collections.jar mysql-connector-java.jar jta.jar commons-digester.jar 然后创建数据名称 testjbpm 编码为gbk ...
jbpm演示demo例子
【jbpm4.0三个例子】是关于jbpm4版本的工作流管理系统实例的分享,主要在MyEclipse 7.5和Eclipse 3.42环境下运行。jbpm(Java Business Process Management)是一个开源的工作流和业务流程管理平台,它提供了一套...
【jbpm3.2.3例子】是一个基于特定技术环境的流程管理实例,它涵盖了jbpm(Java Business Process Management)3.2.3版本的使用,该版本是jbpm流程引擎的一个早期迭代,用于实现业务流程自动化。在这个例子中,我们将...
【jbpm4.4请假例子】是一个基于jbpm4.4流程引擎的示例项目,它展示了一个在Eclipse环境中开发的请假流程。jbPM(Java Business Process Management)是一个开源的工作流和业务流程管理框架,它允许开发者设计、执行...
4. **jBPM数据库表的创建** - **MySQL**:使用`JbpmSessionFactory`的`buildJbpmSessionFactory().getJbpmSchema().dropSchema()`和`createSchema()`方法可以自动创建jBPM所需的数据库表和数据内容。 - **Oracle**...