流程定义部署之后,自然就是流程定义列表了,但和前一节一样的是,这里也是和之前单独的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代码:

[html] view
plain
 copy

  1. <div id="logdiv1" ng-init="init();">
  2. <p style="font-size:24px;margin:3px">流程列表</p>
  3. <center>
  4. <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">
  5. <tr style="background-color:#ccc">
  6. <td>ID</td>
  7. <td>NAME</td>
  8. <td>DeploymentID</td>
  9. <td>KEY</td>
  10. <td>版本号</td>
  11. <td>resourceName</td>
  12. <td>DiagramResourceName</td>
  13. <td>操 作</td>
  14. </tr>
  15. <tr ng-repeat="process in processList | orderBy:'id'" >
  16. <td>{{process.id}}</td>
  17. <td>{{process.name}}</td>
  18. <td>{{process.deploymentId}}</td>
  19. <td>{{process.key}}</td>
  20. <td>{{process.version}}</td>
  21. <td>{{process.resourceName}}</td>
  22. <td>{{process.diagramResourceName}}</td>
  23. <td><a href="script:;" ng-click="toProcess(process)">启动</a>
  24. <a href="script:;" ng-click="deleteProcess(process)">删除</a>
  25. </td>
  26. </tr>
  27. </table>
  28. <div id="handleTemplate" ></div>
  29. </center>
  30. </div>

相应的angularjs代码:

[javascript] view
plain
 copy

  1. angular.module('activitiApp')
  2. .controller('processCtr', ['$rootScope','$scope','$http','$location', function($rootScope,$scope,$http,$location){
  3. $scope.init=function(){
  4. $http.post("./processList.do").success(function(result) {
  5. if(result.isLogin==="yes"){
  6. $rootScope.userName=result.userName;
  7. $scope.processList=result.data;
  8. }else{
  9. $location.path("/login");
  10. }
  11. });
  12. }
  13. //開始流程
  14. $scope.toProcess= function(process){
  15. $rootScope.process=process;
  16. $('#handleTemplate').html('').dialog({
  17. title:'流程名称[' + process.name + ']',
  18. modal: true,
  19. width: $.common.window.getClientWidth() * 0.6,
  20. height: $.common.window.getClientHeight() * 0.9,
  21. open: function() {
  22. // 获取json格式的表单数据。就是流程定义中的全部field
  23. readForm.call(this, process.deploymentId);
  24. },
  25. buttons: [{
  26. text: '启动流程',
  27. click: function() {
  28. $("#handleTemplate").dialog("close");
  29. sendStartupRequest();
  30. setTimeout(function(){
  31. window.location.href =("#/findFirstTask");
  32. },1500);
  33. }
  34. }]
  35. }).position({
  36. //my: "center",
  37. //at: "center",
  38. offset:'300 300',
  39. of: window,
  40. collision:"fit"
  41. });
  42. ;
  43. };
  44. //读取流程启动表单
  45. function readForm(deploymentId) {
  46. var dialog = this;
  47. // 读取启动时的表单
  48. $.post('./getStartForm.do',deploymentId, function(result) {
  49. // 获取的form是字符行,html格式直接显示在对话框内就能够了。然后用form包裹起来
  50. $(dialog).append("<div class='formContent' />");
  51. $('.formContent').html('').wrap("<form id='startform' class='formkey-form' method='post' />");
  52. var $form = $('.formkey-form');
  53. // 设置表单action    getStartFormAndStartProcess
  54. $form.attr('action', './getStartFormAndStartProcess');
  55. //设置部署的Id
  56. $form.append("<input type='hidden' name='deploymentId' value="+deploymentId+">");
  57. $form.append(result.form);
  58. // 初始化日期组件
  59. $form.find('.datetime').datetimepicker({
  60. stepMinute: 5
  61. });
  62. $form.find('.date').datepicker();
  63. // 表单验证
  64. $form.validate($.extend({}, $.common.plugin.validator));
  65. });
  66. }
  67. /**
  68. * 提交表单
  69. * @return {[type]} [description]
  70. */
  71. function sendStartupRequest() {
  72. if ($(".formkey-form").valid()) {
  73. var url = './getStartFormAndStartProcess.do';
  74. var args = $('#startform').serialize();
  75. $.post(url, args, function(data){
  76. $("#handleTemplate").dialog("close");
  77. $location.path("/findFirstTask");
  78. });
  79. }
  80. }
  81. }])

在上边的代码中就有须要注意的地方了,从代码中能够看到。当我们点击页面的启动button时,会触发toProcess方法。而这种方法就使用到了dialog对话框。对话框中显示的内容便是之前自己定义的表单,从后台数据库中请求过来。

那么读取的时候发送了getStartForm.do的请求,后台相应的代码例如以下:

[java] view
plain
 copy

  1. @RequestMapping(value = "/getStartForm.do", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
  2. @ResponseBody
  3. public Object getStartForm(@RequestBody String deploymentId) {
  4. Map<String, String> map = new HashMap<String, String>();
  5. String deString = null;
  6. deString = deploymentId.replaceAll("=", "");
  7. String form = this.getStartForm1(deString);
  8. map.put("form", form);
  9. return map;
  10. }
  11. public String getStartForm1(String deploymentId) {
  12. String deString = null;
  13. deString = deploymentId.replaceAll("=", "");
  14. ProcessDefinition pd = repositoryService.createProcessDefinitionQuery()
  15. .deploymentId(deString).singleResult();
  16. String form = (String) formService.getRenderedStartForm(pd.getId());
  17. return form;
  18. }

要说明的是这里之所以能使用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这里,启动流程实例:

[java] view
plain
 copy

  1. /**
  2. * @throws XMLStreamException
  3. *             启动流程
  4. *
  5. * @author:tuzongxun
  6. * @Title: startProcess
  7. * @param @return
  8. * @return Object
  9. * @date Mar 17, 2016 2:06:34 PM
  10. * @throws
  11. */
  12. @RequestMapping(value = "/getStartFormAndStartProcess.do", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
  13. @ResponseBody
  14. public Object startProcess1(HttpServletRequest req)
  15. throws XMLStreamException {
  16. Map<String, String[]> formMap = req.getParameterMap();
  17. String deploymentId = formMap.get("deploymentId")[0];
  18. // 拿到第一个data_1设置申请人
  19. String person1 = (String) formMap.get("data_1")[0];
  20. Map<String, String> map = new HashMap<String, String>();
  21. boolean isLogin = this.isLogin(req);
  22. if (isLogin) {
  23. if (deploymentId != null) {
  24. HttpSession session = req.getSession();
  25. String assginee = (String) session.getAttribute("userName");
  26. ProcessDefinition pd = repositoryService
  27. .createProcessDefinitionQuery()
  28. .deploymentId(deploymentId).singleResult();
  29. String processDefinitionId = pd.getId();
  30. Map<String, String> formProperties = new HashMap<String, String>();
  31. Iterator<FlowElement> iterator1 = this
  32. .findFlow(processDefinitionId);
  33. // 取第一个节点,開始节点的行号
  34. String row = null;
  35. while (iterator1.hasNext()) {
  36. FlowElement flowElement = iterator1.next();
  37. row = flowElement.getXmlRowNumber() + "";
  38. break;
  39. }
  40. // 从request中读取參数然后转换
  41. Set<Entry<String, String[]>> entrySet = formMap.entrySet();
  42. for (Entry<String, String[]> entry : entrySet) {
  43. String key = entry.getKey();
  44. String value = entry.getValue()[0];
  45. if (!key.equals("deploymentId")) {
  46. String keyString = key + row;
  47. formProperties.put(keyString, value);
  48. }
  49. }
  50. formProperties.put("deploymentId", deploymentId);
  51. Iterator<FlowElement> iterator = this.findFlow(pd.getId());
  52. int i = 1;
  53. while (iterator.hasNext()) {
  54. FlowElement flowElement = iterator.next(); // 申请人
  55. if (flowElement.getClass().getSimpleName()
  56. .equals("UserTask")
  57. && i == 1) {
  58. UserTask userTask = (UserTask) flowElement;
  59. String assignee = userTask.getAssignee();
  60. int index1 = assignee.indexOf("{");
  61. int index2 = assignee.indexOf("}");
  62. formProperties
  63. .put(assignee.substring(index1 + 1, index2),
  64. person1);
  65. break;
  66. }
  67. }
  68. identityService.setAuthenticatedUserId(assginee);
  69. ProcessInstance processInstance = formService
  70. .submitStartFormData(processDefinitionId,
  71. formProperties);
  72. map.put("userName",
  73. (String) req.getSession().getAttribute("userName"));
  74. map.put("isLogin", "yes");
  75. map.put("result", "success");
  76. } else {
  77. map.put("result", "fail");
  78. }
  79. } else {
  80. map.put("isLogin", "no");
  81. }
  82. return map;
  83. }

而这里最重要的是对前台数据的处理,假设大家使用了ueditor插件,会发现他传递到后台的数据是存放在request中的一个map中。而map的key都是data_1、data_2、data_3的形式。

这样问题就来了。到后边对任务进行操作的时候,这些数据还是这样从data_1開始。那么假设我们原样保存到数据库,以后查询时自然就会有问题了。所以这里就依据每一个流程中流程节点行号的唯一性进行了又一次组合,然后把这些数据保存为流程变量。

activiti自己定义流程之整合(五):启动流程时获取自己定义表单的更多相关文章

  1. activiti自定义流程之整合(六):获取我的申请任务

    流程启动后,流程节点便进入到了任务相关的部分.可以看到我之前的做法是在启动节点就绑定了form表单,启动时就填写相关的数据.实际上在之前我的做法是不对开始节点做任何操作,知道任务节点的时候再填写相关的 ...

  2. Activiti+oracle 启动项目时不能自动建表或更新表的问题分析及解决办法

    现象描述:按照正常配置,第一次启动时不能自动建表 关键配置片段如下: <bean id="processEngineConfiguration" class="or ...

  3. angularjs学习第五天笔记(第二篇:表单验证升级篇)

    您好,我是一名后端开发工程师,由于工作需要,现在系统的从0开始学习前端js框架之angular,每天把学习的一些心得分享出来,如果有什么说的不对的地方,请多多指正,多多包涵我这个前端菜鸟,欢迎大家的点 ...

  4. 第一百五十二节,封装库--JavaScript,表单验证--年月日注入

    封装库--JavaScript,表单验证--年月日注入 效果图 html <div id="reg"> <h2 class="tuo"> ...

  5. activiti自己定义流程之整合(四):整合自己定义表单部署流程定义

    综合前几篇博文内容.我想在整合这一部分中应该会有非常多模块会跳过不讲,就如自己定义表单的表单列表那一块,由于这些模块在整合的过程中都差点儿没有什么修改,再多讲也是反复无用功. 正由于如此,在创建了流程 ...

  6. activiti自定义流程之Spring整合activiti-modeler5.16实例(九):历史任务查询

    注:(1)环境搭建:activiti自定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建        (2)创建流程模型:activiti自定义流程之Spring ...

  7. activiti自定义流程之Spring整合activiti-modeler5.16实例(八):完成个人任务

    注:(1)环境搭建:activiti自定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建        (2)创建流程模型:activiti自定义流程之Spring ...

  8. activiti自定义流程之Spring整合activiti-modeler5.16实例(七):任务列表展示

    注:(1)环境搭建:activiti自定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建        (2)创建流程模型:activiti自定义流程之Spring ...

  9. SpringBoot -- 项目结构+启动流程

    一.简述: 项目结构 二.简述:启动流程 说springboot的启动流程,当然少不了springboot启动入口类 @SpringBootApplication public class Sprin ...

随机推荐

  1. 【例题 7-14 UVA-1602】Lattice Animals

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 借鉴网上的题解的. 思路是. 用"标准化"的思想. 确定基准点(0,0) 然后假设(0,0)是第一个连通块. 然 ...

  2. 数据库SQL Server2012笔记(七)——java 程序操作sql server

    1.crud(增删改查)介绍:create/retrieve/update/delete 2.JDBC介绍 1)JDBC(java database connectivity,java数据库连接) 2 ...

  3. [转载]Google Java Style 中文版

    转自:http://www.blogjava.net/zh-weir/archive/2014/02/08/409608.html Google Java Style 中文版     基于官方文档20 ...

  4. OpenShift 自定义 OPENSHIFT_DOCUMENT_ROOT 变量,替换网站根目录路径!

    OpenShift 自定义 OPENSHIFT_DOCUMENT_ROOT 变量,替换网站根目录路径! 预先定义的子目录 :)     DIY: DocumentRoot=${OPENSHIFT_RE ...

  5. 109.vprintf vfprintf vscanf vfscanf

    vprintf //输出到屏幕 int POUT(char *str, ...) { va_list arg_p=NULL; //读取 va_start(arg_p, str); //接受可变参数 i ...

  6. ORACLE11g R2【RAC+ASM→单实例FS】

    ORACLE11g R2[RAC+ASM→单实例FS] 11g R2 RAC+ASMà单实例FS的DG,建议禁用OMF. 本演示案例所用环境:   primary standby OS Hostnam ...

  7. nuxt使用QRCode.js 生成二维码

    QRCode.js 是一个用于生成二维码图片的插件, 官方文档 . 我是在nuxt.js(vue官方的服务端渲染方式)项目里使用的QRCode.js: 第一步:看官方文档: 第二步:下载QRCode. ...

  8. crm2013 查看下拉框的选项

    在CRM2011中,我们非常easy查看下拉框的选择.打开页面,按F12.把光标对准目标,就会显示出详细的选项,如图:' watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi ...

  9. 2013腾讯编程马拉松||HDU 4505 小Q系列故事——电梯里的爱情 水水水

    http://acm.hdu.edu.cn/showproblem.php?pid=4505 题目大意: 电梯最开始在0层,并且最后必须再回到0层才算一趟任务结束.假设在开始的时候已知电梯内的每个人要 ...

  10. 使用Surging Mqtt 开发基于WS的MqttClient客户端

    原文:使用Surging Mqtt 开发基于WS的MqttClient客户端 最近一段时间由于要做一套智能设备系统,而有幸了解到Surging中的Mqtt broker,学习了很多东西本篇文章基于Su ...