activiti自己定义流程之整合(五):启动流程时获取自己定义表单
流程定义部署之后,自然就是流程定义列表了,但和前一节一样的是,这里也是和之前单独的activiti没什么差别。因此也不多说。我们先看看列表页面以及相应的代码,然后在一步步说明点击启动button时怎样调用自己定义的form表单。
流程定义列表页面例如以下:
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" style="border:none; max-width:100%; font-family:Arial; font-size:14px; line-height:26px">
相应的html代码:
- <div id="logdiv1" ng-init="init();">
- <p style="font-size:24px;margin:3px">流程列表</p>
- <center>
- <table border="1px" style="margin-top:1px;width:87%;font-size:14px;text-align:center;margin-top:1px;margin-left:2px;position:relative;float:left;" cellSpacing="0px" cellPadding="0px">
- <tr style="background-color:#ccc">
- <td>ID</td>
- <td>NAME</td>
- <td>DeploymentID</td>
- <td>KEY</td>
- <td>版本号</td>
- <td>resourceName</td>
- <td>DiagramResourceName</td>
- <td>操 作</td>
- </tr>
- <tr ng-repeat="process in processList | orderBy:'id'" >
- <td>{{process.id}}</td>
- <td>{{process.name}}</td>
- <td>{{process.deploymentId}}</td>
- <td>{{process.key}}</td>
- <td>{{process.version}}</td>
- <td>{{process.resourceName}}</td>
- <td>{{process.diagramResourceName}}</td>
- <td><a href="script:;" ng-click="toProcess(process)">启动</a>
- <a href="script:;" ng-click="deleteProcess(process)">删除</a>
- </td>
- </tr>
- </table>
- <div id="handleTemplate" ></div>
- </center>
- </div>
相应的angularjs代码:
- angular.module('activitiApp')
- .controller('processCtr', ['$rootScope','$scope','$http','$location', function($rootScope,$scope,$http,$location){
- $scope.init=function(){
- $http.post("./processList.do").success(function(result) {
- if(result.isLogin==="yes"){
- $rootScope.userName=result.userName;
- $scope.processList=result.data;
- }else{
- $location.path("/login");
- }
- });
- }
- //開始流程
- $scope.toProcess= function(process){
- $rootScope.process=process;
- $('#handleTemplate').html('').dialog({
- title:'流程名称[' + process.name + ']',
- modal: true,
- width: $.common.window.getClientWidth() * 0.6,
- height: $.common.window.getClientHeight() * 0.9,
- open: function() {
- // 获取json格式的表单数据。就是流程定义中的全部field
- readForm.call(this, process.deploymentId);
- },
- buttons: [{
- text: '启动流程',
- click: function() {
- $("#handleTemplate").dialog("close");
- sendStartupRequest();
- setTimeout(function(){
- window.location.href =("#/findFirstTask");
- },1500);
- }
- }]
- }).position({
- //my: "center",
- //at: "center",
- offset:'300 300',
- of: window,
- collision:"fit"
- });
- ;
- };
- //读取流程启动表单
- function readForm(deploymentId) {
- var dialog = this;
- // 读取启动时的表单
- $.post('./getStartForm.do',deploymentId, function(result) {
- // 获取的form是字符行,html格式直接显示在对话框内就能够了。然后用form包裹起来
- $(dialog).append("<div class='formContent' />");
- $('.formContent').html('').wrap("<form id='startform' class='formkey-form' method='post' />");
- var $form = $('.formkey-form');
- // 设置表单action getStartFormAndStartProcess
- $form.attr('action', './getStartFormAndStartProcess');
- //设置部署的Id
- $form.append("<input type='hidden' name='deploymentId' value="+deploymentId+">");
- $form.append(result.form);
- // 初始化日期组件
- $form.find('.datetime').datetimepicker({
- stepMinute: 5
- });
- $form.find('.date').datepicker();
- // 表单验证
- $form.validate($.extend({}, $.common.plugin.validator));
- });
- }
- /**
- * 提交表单
- * @return {[type]} [description]
- */
- function sendStartupRequest() {
- if ($(".formkey-form").valid()) {
- var url = './getStartFormAndStartProcess.do';
- var args = $('#startform').serialize();
- $.post(url, args, function(data){
- $("#handleTemplate").dialog("close");
- $location.path("/findFirstTask");
- });
- }
- }
- }])
在上边的代码中就有须要注意的地方了,从代码中能够看到。当我们点击页面的启动button时,会触发toProcess方法。而这种方法就使用到了dialog对话框。对话框中显示的内容便是之前自己定义的表单,从后台数据库中请求过来。
那么读取的时候发送了getStartForm.do的请求,后台相应的代码例如以下:
- @RequestMapping(value = "/getStartForm.do", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
- @ResponseBody
- public Object getStartForm(@RequestBody String deploymentId) {
- Map<String, String> map = new HashMap<String, String>();
- String deString = null;
- deString = deploymentId.replaceAll("=", "");
- String form = this.getStartForm1(deString);
- map.put("form", form);
- return map;
- }
- public String getStartForm1(String deploymentId) {
- String deString = null;
- deString = deploymentId.replaceAll("=", "");
- ProcessDefinition pd = repositoryService.createProcessDefinitionQuery()
- .deploymentId(deString).singleResult();
- String form = (String) formService.getRenderedStartForm(pd.getId());
- return form;
- }
要说明的是这里之所以能使用formService.getRenderedStartForm方法,便是由于在上一节部署的时候进行了设置,否则这种方法是无法正常使用的。
那么这个对话框弹出界面视图例如以下:
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" style="border:none; max-width:100%; font-family:Arial; font-size:14px; line-height:26px">
须要注意的是dialog的css样式在jquery-ui.css中,不要忘了导入进来。当然了,也能够按自己的喜好改动。
那么填写好相关的数据点击提交,同过上边的js能够知道就走到了后台getStartFormAndStartProcess这里,启动流程实例:
- /**
- * @throws XMLStreamException
- * 启动流程
- *
- * @author:tuzongxun
- * @Title: startProcess
- * @param @return
- * @return Object
- * @date Mar 17, 2016 2:06:34 PM
- * @throws
- */
- @RequestMapping(value = "/getStartFormAndStartProcess.do", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
- @ResponseBody
- public Object startProcess1(HttpServletRequest req)
- throws XMLStreamException {
- Map<String, String[]> formMap = req.getParameterMap();
- String deploymentId = formMap.get("deploymentId")[0];
- // 拿到第一个data_1设置申请人
- String person1 = (String) formMap.get("data_1")[0];
- Map<String, String> map = new HashMap<String, String>();
- boolean isLogin = this.isLogin(req);
- if (isLogin) {
- if (deploymentId != null) {
- HttpSession session = req.getSession();
- String assginee = (String) session.getAttribute("userName");
- ProcessDefinition pd = repositoryService
- .createProcessDefinitionQuery()
- .deploymentId(deploymentId).singleResult();
- String processDefinitionId = pd.getId();
- Map<String, String> formProperties = new HashMap<String, String>();
- Iterator<FlowElement> iterator1 = this
- .findFlow(processDefinitionId);
- // 取第一个节点,開始节点的行号
- String row = null;
- while (iterator1.hasNext()) {
- FlowElement flowElement = iterator1.next();
- row = flowElement.getXmlRowNumber() + "";
- break;
- }
- // 从request中读取參数然后转换
- Set<Entry<String, String[]>> entrySet = formMap.entrySet();
- for (Entry<String, String[]> entry : entrySet) {
- String key = entry.getKey();
- String value = entry.getValue()[0];
- if (!key.equals("deploymentId")) {
- String keyString = key + row;
- formProperties.put(keyString, value);
- }
- }
- formProperties.put("deploymentId", deploymentId);
- Iterator<FlowElement> iterator = this.findFlow(pd.getId());
- int i = 1;
- while (iterator.hasNext()) {
- FlowElement flowElement = iterator.next(); // 申请人
- if (flowElement.getClass().getSimpleName()
- .equals("UserTask")
- && i == 1) {
- UserTask userTask = (UserTask) flowElement;
- String assignee = userTask.getAssignee();
- int index1 = assignee.indexOf("{");
- int index2 = assignee.indexOf("}");
- formProperties
- .put(assignee.substring(index1 + 1, index2),
- person1);
- break;
- }
- }
- identityService.setAuthenticatedUserId(assginee);
- ProcessInstance processInstance = formService
- .submitStartFormData(processDefinitionId,
- formProperties);
- map.put("userName",
- (String) req.getSession().getAttribute("userName"));
- map.put("isLogin", "yes");
- map.put("result", "success");
- } else {
- map.put("result", "fail");
- }
- } else {
- map.put("isLogin", "no");
- }
- return map;
- }
而这里最重要的是对前台数据的处理,假设大家使用了ueditor插件,会发现他传递到后台的数据是存放在request中的一个map中。而map的key都是data_1、data_2、data_3的形式。
这样问题就来了。到后边对任务进行操作的时候,这些数据还是这样从data_1開始。那么假设我们原样保存到数据库,以后查询时自然就会有问题了。所以这里就依据每一个流程中流程节点行号的唯一性进行了又一次组合,然后把这些数据保存为流程变量。
activiti自己定义流程之整合(五):启动流程时获取自己定义表单的更多相关文章
- activiti自定义流程之整合(六):获取我的申请任务
流程启动后,流程节点便进入到了任务相关的部分.可以看到我之前的做法是在启动节点就绑定了form表单,启动时就填写相关的数据.实际上在之前我的做法是不对开始节点做任何操作,知道任务节点的时候再填写相关的 ...
- Activiti+oracle 启动项目时不能自动建表或更新表的问题分析及解决办法
现象描述:按照正常配置,第一次启动时不能自动建表 关键配置片段如下: <bean id="processEngineConfiguration" class="or ...
- angularjs学习第五天笔记(第二篇:表单验证升级篇)
您好,我是一名后端开发工程师,由于工作需要,现在系统的从0开始学习前端js框架之angular,每天把学习的一些心得分享出来,如果有什么说的不对的地方,请多多指正,多多包涵我这个前端菜鸟,欢迎大家的点 ...
- 第一百五十二节,封装库--JavaScript,表单验证--年月日注入
封装库--JavaScript,表单验证--年月日注入 效果图 html <div id="reg"> <h2 class="tuo"> ...
- activiti自己定义流程之整合(四):整合自己定义表单部署流程定义
综合前几篇博文内容.我想在整合这一部分中应该会有非常多模块会跳过不讲,就如自己定义表单的表单列表那一块,由于这些模块在整合的过程中都差点儿没有什么修改,再多讲也是反复无用功. 正由于如此,在创建了流程 ...
- activiti自定义流程之Spring整合activiti-modeler5.16实例(九):历史任务查询
注:(1)环境搭建:activiti自定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建 (2)创建流程模型:activiti自定义流程之Spring ...
- activiti自定义流程之Spring整合activiti-modeler5.16实例(八):完成个人任务
注:(1)环境搭建:activiti自定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建 (2)创建流程模型:activiti自定义流程之Spring ...
- activiti自定义流程之Spring整合activiti-modeler5.16实例(七):任务列表展示
注:(1)环境搭建:activiti自定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建 (2)创建流程模型:activiti自定义流程之Spring ...
- SpringBoot -- 项目结构+启动流程
一.简述: 项目结构 二.简述:启动流程 说springboot的启动流程,当然少不了springboot启动入口类 @SpringBootApplication public class Sprin ...
随机推荐
- 洛谷 P3654 First Step (ファーストステップ)
洛谷 P3654 First Step (ファーストステップ) https://www.luogu.org/problemnew/show/P3654 题目描述 可是……这个篮球场,好像很久没有使用过 ...
- Apache httpd.conf 配置文件语法验证
Apache 的 httpd.conf文件改动之后,必须重新启动server才干生效. 有时server在提供服务的时候,直接更改配置,重新启动服务.会带来非常大的危急性. 假设能在改动配置之后,先验 ...
- x264代码剖析(三):主函数main()、解析函数parse()与编码函数encode()
x264代码剖析(三):主函数main().解析函数parse()与编码函数encode() x264的入口函数为main().main()函数首先调用parse()解析输入的參数,然后调用encod ...
- debian 9 安装后需做的几件事
debian 9 安装后需做的几件事 安装环境:X86 >> Debian 9 Linux/GNU apt源更新 注意连上有线网络 刚安装好的debian系统中,/etc/apt/sour ...
- Android SimpleAdapter
1.MainActivity.java public class MainActivity extends Activity { private ListView listView; private ...
- 学习笔记:Vue——混入
前言: 到现在用Vue做了不少项目了,用到的都是初阶的功能,很多高阶能力都没有用到.仅用初级阶段也能做项目,甚至是复杂项目,可见vue之强大,果然是渐进式开发方式. 但是本着虚心学习的态度,还是要抽空 ...
- AspJpeg2.0组件教程完整版 aspjpeg教程...
AspJpeg是一款功能强大的基于Microsoft IIS环境的图片处理组件,网络上对其进行详细和深入介绍的中文文章并不多,即使有一般也只是牵涉到图片缩略图和图片水印,这与其为英文版本有着密切的关系 ...
- 具体解释。。设计模式5——DAO。。studying
设计模式5--DAO ★ 场景和问题 在Java程序中,常常须要把数据持久化.也须要获取持久化的数据,可是在进行数据持久化的过程中面临诸多问题 (如:数据源不同.存储类型不同.供应商不同.訪问方式不同 ...
- 自己定义Dialog的具体步骤(实现自己定义样式一般原理)
转载请标注转载http://blog.csdn.net/oqihaogongyuan/article/details/50958659 自己定义Dialog的具体步骤(实现自己定义样式一般原理) ...
- [TypeScript] Sharing Class Behavior with Inheritance in TypeScript
Typescript classes make inheritance much easier to write and understand. In this lesson we look into ...