jbpm 工作流(二)
1 概述
本文主要介绍如何将JBPM+Struts+Spring+Hibernate整合在一块。并通过一个简单实例来说明。此实例为一个申请审批的简单流程,并将申请人和审批人记录到数据库中,流程为start----申请----审批----end,中间无退回,无分支,只是看一下jbpm的流程设计,本文将jbpm和struts/spring/hibernate结合在一块做为一个完整的项目来叙述。
通过processdefinition.xml的可视图,可了解一下流程图:
2 环境
tomcat6.0+jdk1.5+eclips3.2
jbpm3.1.4
spring2.0
hibernate3
数据库:postgreSql8.1
jbpm提供了在eclipse下的一个可视化插件,通过它我们可以方便的定义工作流,介绍一下eclipse如何添加该插件?
打开jbpm-starters-kit-3.1.4\jbpm-designer\jbpm-gpd-feature目录,我们可以看到下面有一个eclipse文件夹,这里我们通过link的方式为eclipse添加该插件。
在{eclipse_home}/link文件夹下新建jbpm-designer.link文件,用记事本打开该文件加入如下一行:
path=D:\\jbpm-starters-kit-3.1.4\\jbpm-designer\\jbpm-gpd-feature
后面的路径即为该插件的存放路径,根据个人情况修改。注意,这里的分隔符使用双斜杠\\或者用单斜杠/。
3 项目总体结构
src部分
WebRoot部分:
4 要引入的jar包
很多jar包是从jbpm-starters-kit-3.1.4\jbpm-starters-kit-3.1.4\jbpm\build
和jbpm-starters-kit-3.1.4\jbpm-starters-kit-3.1.4\jbpm\lib中得到的
其中spring-modules-jbpm31.jar、postgresql-8.1-405.jdbc2.jar要下载
以下是myeclips需要引入的包
5 web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4"xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>/jbpm/</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>60000</param-value>
</context-param>
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>com.binghe.pub.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>3</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>3</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet>
<servlet-name>imageServlet</servlet-name>
<servlet-class>com.binghe.pub.ImageServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>imageServlet</servlet-name>
<url-pattern>/servlet/imageServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/apply.jsp</welcome-file>
</welcome-file-list>
</web-app>
6 applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN""http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="dataSource"class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>org.postgresql.Driver</value>
</property>
<property name="url">
<value>jdbc:postgresql://localhost:5432/jbpmtest</value>
</property>
<property name="username">
<value>admin</value>
</property>
<property name="password">
<value>admin</value>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="mappingLocations">
<value>classpath*:/org/jbpm/**/*.hbm.xml</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.PostgreSQLDialect
</prop>
<prop key="jdbc.fetch_size">50</prop>
<prop key="jdbc.batch_size">30</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.use_outer_join">true</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">
true
</prop>
</props>
</property>
</bean>
<!-- Transaction Manager -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<!-- Transaction Interceptor -->
<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor"
dependency-check="none">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="attachDirty*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<!-- default, readOnly -->
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<!-- reading jBPM process definitions -->
<bean id="websaleWorkflow1"
class="org.springmodules.workflow.jbpm31.definition.ProcessDefinitionFactoryBean">
<property name="definitionLocation"
value="classpath:/com/jpdl/simple/processdefinition.xml" />
</bean>
<!-- jBPM configuration-->
<bean id="jbpmConfiguration"
class="org.springmodules.workflow.jbpm31.LocalJbpmConfigurationFactoryBean">
<property name="sessionFactory" ref="sessionFactory" />
<property name="configuration" value="classpath:/jbpm.cfg.xml" />
<property name="processDefinitions">
<list>
<ref local="websaleWorkflow1" />
</list>
</property>
<property name="createSchema" value="true" />
</bean>
<!-- jBPM template -->
<bean id="jbpmTemplate"
class="org.springmodules.workflow.jbpm31.JbpmTemplate">
<constructor-arg index="0" ref="jbpmConfiguration" />
<constructor-arg index="1" ref="websaleWorkflow1" />
</bean>
<bean id="JbpmDAO" class="com.binghe.hibernate.dao.JbpmDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
<property name="jbpmConfiguration">
<ref bean="jbpmConfiguration" />
</property>
</bean>
<bean name="/jbpm" class="com.binghe.struts.action.JbpmAction"
singleton="false">
<property name="jbpmDAO">
<ref bean="JbpmDAO" />
</property>
</bean>
</beans>
7 struts-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<data-sources />
<form-beans>
<form-bean name="jbpmForm" type="com.binghe.struts.form.JbpmForm" />
</form-beans>
<global-exceptions />
<global-forwards>
<forward name="error" path="/info/error.jsp" />
</global-forwards>
<action-mappings>
<action
attribute="jbpmForm"
input="/approve.jsp"
name="jbpmForm"
parameter="method"
path="/jbpm"
scope="request"
type="org.springframework.web.struts.DelegatingActionProxy"
validate="false">
<forward name="approve" path="/approve.jsp" />
<forward name="end" path="/end.jsp" />
</action>
</action-mappings>
<message-resources parameter="ApplicationResources" />
<plug-in
className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/classes/applicationContext.xml" />
</plug-in>
</struts-config>
8 processdefinition.xml
<?xml version="1.0" encoding="GBK"?>
<process-definition xmlns="urn:jbpm.org:jpdl-3.1" name="helloworld">
<start-state name="start">
<transition name="to_apply" to="申请"></transition>
</start-state>
<!-- 申请 -->
<task-node name="申请" signal="last-wait" create-tasks="false">
<task name="申请"></task>
<!-- 流程转向 -->
<transition name="to_approve" to="审批"></transition>
</task-node>
<!-- 审批 -->
<task-node name="审批" signal="last-wait" create-tasks="false">
<task name="审批"></task>
<transition name="to_end" to="end1"></transition>
</task-node>
<end-state name="end1"></end-state>
</process-definition>
9 hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- jdbc connection properties -->
<propertyname="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<propertyname="hibernate.connection.driver_class">org.postgresql.Driver</property>
<propertyname="hibernate.connection.url">jdbc:postgresql://localhost:5432/jbpmtest</property>
<property name="hibernate.connection.username">admin</property>
<property name="hibernate.connection.password">admin</property>
<!--<property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>-->
<!-- ############################################ -->
<!-- # mapping files with external dependencies # -->
<!-- ############################################ -->
<!-- following mapping file has a dependendy on -->
<!-- 'bsh-{version}.jar'. -->
<!-- uncomment this if you don't have bsh on your -->
<!-- classpath. you won't be able to use the -->
<!-- script element in process definition files -->
<mapping resource="org/jbpm/graph/action/Script.hbm.xml"/>
<!-- following mapping files have a dependendy on -->
<!-- 'jbpm-identity-{version}.jar', mapping files -->
<!-- of the pluggable jbpm identity component. -->
<!-- comment out the following 3 lines if you don't-->
<!-- want to use the default jBPM identity mgmgt -->
<!-- component -->
<mapping resource="org/jbpm/identity/User.hbm.xml"/>
<mapping resource="org/jbpm/identity/Group.hbm.xml"/>
<mapping resource="org/jbpm/identity/Membership.hbm.xml"/>
<!-- ###################### -->
<!-- # jbpm mapping files # -->
<!-- ###################### -->
<!-- hql queries and type defs -->
<mapping resource="org/jbpm/db/hibernate.queries.hbm.xml" />
<!-- graph.def mapping files -->
<mapping resource="org/jbpm/graph/def/ProcessDefinition.hbm.xml"/>
<mapping resource="org/jbpm/graph/def/Node.hbm.xml"/>
<mapping resource="org/jbpm/graph/def/Transition.hbm.xml"/>
<mapping resource="org/jbpm/graph/def/Event.hbm.xml"/>
<mapping resource="org/jbpm/graph/def/Action.hbm.xml"/>
<mapping resource="org/jbpm/graph/def/SuperState.hbm.xml"/>
<mapping resource="org/jbpm/graph/def/ExceptionHandler.hbm.xml"/>
<mapping resource="org/jbpm/instantiation/Delegation.hbm.xml"/>
<!-- graph.node mapping files -->
<mapping resource="org/jbpm/graph/node/StartState.hbm.xml"/>
<mapping resource="org/jbpm/graph/node/EndState.hbm.xml"/>
<mapping resource="org/jbpm/graph/node/ProcessState.hbm.xml"/>
<mapping resource="org/jbpm/graph/node/Decision.hbm.xml"/>
<mapping resource="org/jbpm/graph/node/Fork.hbm.xml"/>
<mapping resource="org/jbpm/graph/node/Join.hbm.xml"/>
<mapping resource="org/jbpm/graph/node/State.hbm.xml"/>
<mapping resource="org/jbpm/graph/node/TaskNode.hbm.xml"/>
<!-- context.def mapping files -->
<mapping resource="org/jbpm/context/def/ContextDefinition.hbm.xml"/>
<mapping resource="org/jbpm/context/def/VariableAccess.hbm.xml"/>
<!-- taskmgmt.def mapping files -->
<mapping resource="org/jbpm/taskmgmt/def/TaskMgmtDefinition.hbm.xml"/>
<mapping resource="org/jbpm/taskmgmt/def/Swimlane.hbm.xml"/>
<mapping resource="org/jbpm/taskmgmt/def/Task.hbm.xml"/>
<mapping resource="org/jbpm/taskmgmt/def/TaskController.hbm.xml"/>
<!-- module.def mapping files -->
<mapping resource="org/jbpm/module/def/ModuleDefinition.hbm.xml"/>
<!-- bytes mapping files -->
<mapping resource="org/jbpm/bytes/ByteArray.hbm.xml"/>
<!-- file.def mapping files -->
<mapping resource="org/jbpm/file/def/FileDefinition.hbm.xml"/>
<!-- scheduler.def mapping files -->
<mapping resource="org/jbpm/scheduler/def/CreateTimerAction.hbm.xml"/>
<mapping resource="org/jbpm/scheduler/def/CancelTimerAction.hbm.xml"/>
<!-- graph.exe mapping files -->
<mapping resource="org/jbpm/graph/exe/Comment.hbm.xml"/>
<mapping resource="org/jbpm/graph/exe/ProcessInstance.hbm.xml"/>
<mapping resource="org/jbpm/graph/exe/Token.hbm.xml"/>
<mapping resource="org/jbpm/graph/exe/RuntimeAction.hbm.xml"/>
<!-- module.exe mapping files -->
<mapping resource="org/jbpm/module/exe/ModuleInstance.hbm.xml"/>
<!-- context.exe mapping files -->
<mapping resource="org/jbpm/context/exe/ContextInstance.hbm.xml"/>
<mapping resource="org/jbpm/context/exe/TokenVariableMap.hbm.xml"/>
<mapping resource="org/jbpm/context/exe/VariableInstance.hbm.xml"/>
<mappingresource="org/jbpm/context/exe/variableinstance/ByteArrayInstance.hbm.xml"/>
<mappingresource="org/jbpm/context/exe/variableinstance/DateInstance.hbm.xml"/>
<mappingresource="org/jbpm/context/exe/variableinstance/DoubleInstance.hbm.xml"/>
<mappingresource="org/jbpm/context/exe/variableinstance/HibernateLongInstance.hbm.xml"/>
<mappingresource="org/jbpm/context/exe/variableinstance/HibernateStringInstance.hbm.xml"/>
<mappingresource="org/jbpm/context/exe/variableinstance/LongInstance.hbm.xml"/>
<mappingresource="org/jbpm/context/exe/variableinstance/NullInstance.hbm.xml"/>
<mappingresource="org/jbpm/context/exe/variableinstance/StringInstance.hbm.xml"/>
<!-- msg.db mapping files -->
<mapping resource="org/jbpm/msg/Message.hbm.xml"/>
<mapping resource="org/jbpm/msg/db/TextMessage.hbm.xml"/>
<mapping resource="org/jbpm/command/ExecuteActionCommand.hbm.xml"/>
<mapping resource="org/jbpm/command/ExecuteNodeCommand.hbm.xml"/>
<mapping resource="org/jbpm/command/SignalCommand.hbm.xml"/>
<mapping resource="org/jbpm/command/TaskInstanceEndCommand.hbm.xml"/>
<!-- taskmgmt.exe mapping files -->
<mapping resource="org/jbpm/taskmgmt/exe/TaskMgmtInstance.hbm.xml"/>
<mapping resource="org/jbpm/taskmgmt/exe/TaskInstance.hbm.xml"/>
<mapping resource="org/jbpm/taskmgmt/exe/PooledActor.hbm.xml"/>
<mapping resource="org/jbpm/taskmgmt/exe/SwimlaneInstance.hbm.xml"/>
<!-- scheduler.exe mapping files -->
<mapping resource="org/jbpm/scheduler/exe/Timer.hbm.xml"/>
<!-- logging mapping files -->
<mapping resource="org/jbpm/logging/log/ProcessLog.hbm.xml"/>
<mapping resource="org/jbpm/logging/log/MessageLog.hbm.xml"/>
<mapping resource="org/jbpm/logging/log/CompositeLog.hbm.xml"/>
<mapping resource="org/jbpm/graph/log/ActionLog.hbm.xml"/>
<mapping resource="org/jbpm/graph/log/NodeLog.hbm.xml"/>
<mapping resource="org/jbpm/graph/log/ProcessInstanceCreateLog.hbm.xml"/>
<mapping resource="org/jbpm/graph/log/ProcessInstanceEndLog.hbm.xml"/>
<mapping resource="org/jbpm/graph/log/ProcessStateLog.hbm.xml"/>
<mapping resource="org/jbpm/graph/log/SignalLog.hbm.xml"/>
<mapping resource="org/jbpm/graph/log/TokenCreateLog.hbm.xml"/>
<mapping resource="org/jbpm/graph/log/TokenEndLog.hbm.xml"/>
<mapping resource="org/jbpm/graph/log/TransitionLog.hbm.xml"/>
<mapping resource="org/jbpm/context/log/VariableLog.hbm.xml"/>
<mapping resource="org/jbpm/context/log/VariableCreateLog.hbm.xml"/>
<mapping resource="org/jbpm/context/log/VariableDeleteLog.hbm.xml"/>
<mapping resource="org/jbpm/context/log/VariableUpdateLog.hbm.xml"/>
<mappingresource="org/jbpm/context/log/variableinstance/ByteArrayUpdateLog.hbm.xml"/>
<mappingresource="org/jbpm/context/log/variableinstance/DateUpdateLog.hbm.xml"/>
<mappingresource="org/jbpm/context/log/variableinstance/DoubleUpdateLog.hbm.xml"/>
<mappingresource="org/jbpm/context/log/variableinstance/HibernateLongUpdateLog.hbm.xml"/>
<mappingresource="org/jbpm/context/log/variableinstance/HibernateStringUpdateLog.hbm.xml"/>
<mappingresource="org/jbpm/context/log/variableinstance/LongUpdateLog.hbm.xml"/>
<mappingresource="org/jbpm/context/log/variableinstance/StringUpdateLog.hbm.xml"/>
<mapping resource="org/jbpm/taskmgmt/log/TaskLog.hbm.xml"/>
<mapping resource="org/jbpm/taskmgmt/log/TaskCreateLog.hbm.xml"/>
<mapping resource="org/jbpm/taskmgmt/log/TaskAssignLog.hbm.xml"/>
<mapping resource="org/jbpm/taskmgmt/log/TaskEndLog.hbm.xml"/>
<mapping resource="org/jbpm/taskmgmt/log/SwimlaneLog.hbm.xml"/>
<mapping resource="org/jbpm/taskmgmt/log/SwimlaneCreateLog.hbm.xml"/>
<mapping resource="org/jbpm/taskmgmt/log/SwimlaneAssignLog.hbm.xml"/>
</session-factory>
</hibernate-configuration>
10 代码说明
10.1代码包结构
在src/com/目录下面,有包
com.binghe.hibernate.dao 存放dao类,调用jbpm的方法操作数据库
com.binghe.pub 存放公共的信息,如字符集乱码的处理等等,不用的话可以在web.xml中不加载,本文不赘述。
com.binghe.struts.action 存放sturts中的action,与jsp页面交互
com.binghe.struts.form 存放sturts中的form,存放jsp页面中的提交数据
com.binghe.jpdl 存放jbpm的流程文件
Jsp部分:
apply.jsp 申请jsp,输入申请人,web.xml中已将此页面为welcome页面
approve.jsp 审批jsp,输入审批人
end.jsp 结束jsp,显示申请人和审批人
10.2完整代码
10.2.1 JbpmDAO
package com.binghe.hibernate.dao;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
import org.jbpm.db.GraphSession;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.graph.exe.Token;
import org.jbpm.graph.node.TaskNode;
import org.jbpm.taskmgmt.def.Task;
import org.jbpm.taskmgmt.exe.TaskMgmtInstance;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
public class JbpmDAO extends HibernateDaoSupport {
private static final Log log = LogFactory.getLog(JbpmDAO.class);
JbpmConfiguration jbpmConfiguration = null;
protected void initDao() {
// do nothing
}
/**
* start节点
* signal()之后,节点流向start---->申请
*
*/
public Long apply(String applyName) {
JbpmContext jbpmContext = jbpmConfiguration.getCurrentJbpmContext();
Long id=null;
if(jbpmContext==null){
jbpmContext = jbpmConfiguration.createJbpmContext();
}
try{
GraphSession graphSession = jbpmContext.getGraphSession();
//通过名称查询出所需要的流程,也可以通过id查询
ProcessDefinition processDefinition = graphSession
.findLatestProcessDefinition("helloworld");
//创建一个新流程
ProcessInstance processInstance = newProcessInstance(processDefinition);
id = processInstance.getId();
//请假申请结束,转到下一个流程结点
processInstance.getRootToken().signal();
//创建任务,并指定用户,数据库中记录是那个用户提出的申请
TaskNode taskNode = (TaskNode)processInstance.getRootToken().getNode();
Task task = (Task)taskNode.getTasks().iterator().next();
Token token = processInstance.getRootToken();
TaskMgmtInstance taskInstance =processInstance.getTaskMgmtInstance();
taskInstance.createTaskInstance(task, token).setActorId(applyName);
jbpmContext.save(processInstance);
}
finally{
jbpmContext.close();
}
return id;
}
/**
* 审批节点
*signal()之后,节点流向:审批------>end
*/
public void approve(String approveName,Long id) {
JbpmContext jbpmContext = jbpmConfiguration.getCurrentJbpmContext();
if(jbpmContext==null){
jbpmContext = jbpmConfiguration.createJbpmContext();
}
try{
//通过当前流程实例的id查询出流程
ProcessInstance processInstance =jbpmContext.loadProcessInstance(id);
processInstance.getRootToken().signal();
//创建任务,并指定用户,数据库中记录是那个用户做的审批
TaskNode taskNode = (TaskNode)processInstance.getRootToken().getNode();
Task task = (Task)taskNode.getTasks().iterator().next();
Token token = processInstance.getRootToken();
TaskMgmtInstance taskInstance = processInstance.getTaskMgmtInstance();
taskInstance.createTaskInstance(task, token).setActorId(approveName);
jbpmContext.save(processInstance);
}
finally{
jbpmContext.close();
}
}
public static JbpmDAO getFromApplicationContext(ApplicationContext ctx) {
return (JbpmDAO) ctx.getBean("JbpmDAO");
}
public JbpmConfiguration getJbpmConfiguration() {
return jbpmConfiguration;
}
public void setJbpmConfiguration(JbpmConfiguration jbpmConfiguration) {
this.jbpmConfiguration = jbpmConfiguration;
}
}
10.2.2 JbpmAction
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.binghe.struts.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import com.binghe.hibernate.dao.JbpmDAO;
import com.binghe.struts.form.JbpmForm;
public class JbpmAction extends DispatchAction {
private JbpmDAO jbpmDAO = null;
/**
* 申请,
*
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward apply(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
JbpmForm jbpmForm = (JbpmForm) form;
try {
String applyName = jbpmForm.getApplyName();
Long id = this.jbpmDAO.apply(applyName);
jbpmForm.setId(id);
} catch (Exception e) {
e.printStackTrace();
}
return mapping.findForward("approve");
}
/**
* 审批
*
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward approve(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
JbpmForm jbpmForm = (JbpmForm) form;
try {
// 审批人
String approveName =jbpmForm.getApproveName();
Long id = jbpmForm.getId();
this.jbpmDAO.approve(approveName, id);
} catch (Exception e) {
e.printStackTrace();
}
return mapping.findForward("end");
}
public ActionForward end(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
JbpmForm jbpmForm = (JbpmForm) form;
try {
//申请人
jbpmForm.setApplyName(jbpmForm.getApplyName());
// 审批人
jbpmForm.setApproveName(jbpmForm.getApproveName());
} catch (Exception e) {
e.printStackTrace();
}
return mapping.findForward("end");
}
public JbpmDAO getJbpmDAO() {
return jbpmDAO;
}
public void setJbpmDAO(JbpmDAO jbpmDAO) {
this.jbpmDAO = jbpmDAO;
}
}
10.2.3 JbpmForm
package com.binghe.struts.form;
import org.apache.struts.action.ActionForm;
public class JbpmForm extends ActionForm {
private Long id;
private String applyName;
private String approveName;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getApplyName() {
return applyName;
}
public void setApplyName(String applyName) {
this.applyName = applyName;
}
public String getApproveName() {
return approveName;
}
public void setApproveName(String approveName) {
this.approveName = approveName;
}
}
10.2.4 apply.jsp
<%@ page language="java" contentType="text/html; charset=GBK" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html:html>
<head>
<title>jbpm</title>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" >
<html:form action="/jbpm.do?method=apply" method="post" styleId="form1">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="50" colspan="1" align="center" bgcolor="#F5F5f5">申请人:</td>
<td height="50" colspan="1" align="center" bgcolor="#F5F5f5">
<html:text property="applyName" name="jbpmForm"/>
</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="50" colspan="2" align="center" bgcolor="#F5F5f5">
<input type="submit" name="Submit" id="btn" value=" 申请 "></td>
</tr>
</table>
</html:form>
</body>
</html:html>
10.2.5 approve.jsp
<%@ page language="java" contentType="text/html; charset=GBK" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html:html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>jbpm</title>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" >
<html:form action="/jbpm.do?method=approve" method="post" styleId="form1">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="50" colspan="1" align="center" bgcolor="#F5F5f5">申请人:</td>
<td height="50" colspan="1" align="center" bgcolor="#F5F5f5">
<html:text property="applyName" name="jbpmForm" readonly="true"/>
</td>
</tr>
<tr>
<td height="50" colspan="1" align="center" bgcolor="#F5F5f5">审批人:</td>
<td height="50" colspan="1" align="center"bgcolor="#F5F5f5">
<html:text property="approveName" name="jbpmForm"/>
</td>
</tr>
<tr>
<td>
<html:hidden property="id" name="jbpmForm"/>
</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="50" colspan="2" align="center" bgcolor="#F5F5f5"><input type="submit" name="Submit" id="btn" value=" 审批 "></td>
</tr>
</table>
</html:form>
</body>
</html:html>
10.2.6 end.jsp
<%@ page language="java" contentType="text/html; charset=GBK" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html:html>
<head>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" >
<html:form action="/jbpm.do?method=end" method="post" styleId="form1">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="50" colspan="1" align="center" bgcolor="#F5F5f5">申请人:</td>
<td height="50" colspan="1" align="center" bgcolor="#F5F5f5">
<bean:write property="applyName" name="jbpmForm"/>
</td>
</tr>
<tr>
<td height="50" colspan="1" align="center" bgcolor="#F5F5f5">审批人:</td>
<td height="50" colspan="1" align="center"bgcolor="#F5F5f5">
<bean:write property="approveName" name="jbpmForm"/>
</td>
</tr>
</table>
</html:form>
</body>
</html:html>
11 系统操作页面
输入http://localhost:8080/jbpm/
录入:娄伟征,点击【申请】
录入:刘经理,点击【审批】
12 数据库记录
jbpm_node表
jbpm_processdefinition表
jbpm_processinstance表
jbpm_task表
jbpm_taskinstance表
jbpm_token表
jbpm_transition表
jbpm 工作流(二)的更多相关文章
- Jbpm工作流(一)
了解一下什么是Jbpm及特点. jBPM,全称是Java Business Process Management,是一种基于J2EE的轻量级工作流管理系统.jBPM是公开源代码项目,它使用要遵循 Ap ...
- JBPM——工作流概念
一.概念 工作流(Workflow),就是"业务过程的部分或总体在计算机应用环境下的自己主动化",它主要解决的是"使在多个參与者之间依照某种提前定义的规 ...
- JBPM工作流入门总结
关于JBPM工作流 1.工作流 工作流是一项分离业务操作和系统流程的技术.工作流由实体(Entity).参与者(Participant).流程定义(Flow Definition).工作流引擎(Eng ...
- 转发 JBPM工作流小结
JBoss 题记:某部门领导有天突发奇想,把我们几个人叫过去,曰:最近出去开会,老有人推销自己的工作流产品,说的这好那好,你们几个给我研究研究.正好刚做完的xxx子系统里有一个申请审批的流程,你们按这 ...
- JBPM工作流(二)——数据库表说明
以下为JBMP的数据库说明(18张): 1 流程配置类数据库表: 1.1 JBPM_PROCESSDEFINITION:流程模版表 字段名 字段含义 主键 外键 ID_ 流程模版标识 √ × NAME ...
- JBPM工作流
一.开发环境的搭建 1.下载Jbpm4.4 1.1下载地址: https://sourceforge.net/projects/jbpm/files/jBPM%204/jbpm-4.4/ 1.2解压后 ...
- JBPM工作流(一)——实现一个简单的工作流例子
一.JBPM定义 JBPM,全称是Java Business Process Management(业务流程管理),它是覆盖了业务流程管理.工作流.服务协作等领域的一个开源的.灵活的.易扩展的可执行流 ...
- 【Java EE 学习 67 下】【OA项目练习】【SSH整合JBPM工作流】【JBPM项目实战】
一.SSH整合JBPM JBPM基础见http://www.cnblogs.com/kuangdaoyizhimei/p/4981551.html 现在将要实现SSH和JBPM的整合. 1.添加jar ...
- 【Java EE 学习 67 上】【OA项目练习】【JBPM工作流的使用】
OA项目中有极大可能性使用到JBPM框架解决流程控制问题,比如请假流程.报销流程等等. JBPM:JBoss Business Process Management,翻译过来就是业务流程管理.实际上就 ...
随机推荐
- UNIX网络编程——客户/服务器程序设计示范(八)
TCP预先创建线程服务器程序,主线程统一accept 最后一个使用线程的服务器程序设计示范是在程序启动阶段创建一个线程池之后只让主线程调用accept并把每个客户连接传递给池中某个可用线程. ...
- UNIX网络编程——使用线程的TCP回射服务器程序
同一进程内的所有线程除了共享全局变量外还共享: (1)进程指令: (2)大多数数据: (3) 打开的文件(即描述符): (4)信号处理函数和信号处置: (5)当前工作目录: (6)用户ID和组ID. ...
- Spark:大数据的电花火石!
什么是Spark?可能你很多年前就使用过Spark,反正当年我四六级单词都是用的星火系列,没错,星火系列的洋名就是Spark. 当然这里说的Spark指的是Apache Spark,Apache Sp ...
- mysql的left jion:就是left outer join(right join同理)
左外连接: A left jion B on A.id=B.id 就是A表数据不动,将B表里面能和A对应上的数据补充到A表数据后 而右外连接: rignt jion 则是将A补充到B,B不动,保存全部 ...
- UNIX环境高级编程——信号
一.信号生命周期 从信号发送到信号处理函数的执行完毕. 对于一个完整的信号生命周期(从信号发送到相应的处理函数执行完毕)来说,可以分为三个重要的阶段,这三个阶段由四个重要事件来刻画:信号诞生:信号在进 ...
- 类装载器DexClassLoader (android内核剖析)
在java环境中,有个概念叫做"类装载器",其作用是动态装载Class文件.标准的java SDK中有一个ClassLoader类,借助它可以装载 想要的Class文件,每个Cla ...
- ZooKeeper实现命名服务
使用场景 命名服务就是提供名称的服务,Zookeeper的命名服务有两个应用方面.一个是提供类似JNDI功能,另一个是制作分布式的序列号生成器. JNDI功能,我们利用Zookeep ...
- 9.6、Libgdx之罗盘
(官网:www.libgdx.cn) 有些Android和iOS设备可能需要检测使用罗盘检测方向. 注意:罗盘当前在iOS设备中不可用,RoboVM暂不支持. 查询当前罗盘当前是否可用: boolea ...
- Unity热更新之C#反射动态获取类属性及方法
如果我们要为发布出去的游戏更新一些功能,但又不想让用户重新下载整个游戏包,只让他下载我们更新的资源包,用assetBundle打包资源的方式是可以的,但其中有个最大的例外,那就是脚本. 虽然asset ...
- Swift基础之UITextField
//设置全局变量,将下面的替换即可 //var myTextField = UITextField(); //系统生成的viewDidLoad()方法 override fun ...