flowable 流程表单_flowable笔记 - 加入form引擎

依赖

在之前的基础上:flowable-spring-boot-starter-process flowable笔记 - 环境配置

org.flowable

flowable-form-spring-configurator

6.4.0

流程和表单定义

bpmn20文件

官方那种使用包裹在startEvent里的方式,无法用代码获取表单,可能是用法不正确。

流程和表单放在一起

...

name="Speaker"

variable="SpeakerName"

type="string" />

type="date"

datePattern="dd-MMM-yyyy" />

...

表单单独存放

flowable:class="com.baison.bap.flowable.delegate.FormViewDelegate"/>

test.form

与bpmn20文件里的flowable:formKey对应

需要放在resources/forms文件夹下

表单字段名需要全局唯一,因为值是存在流程variables里的,如果重复,会有被覆盖的情况。

{

"key": "test",

"name": "请假流程",

"fields": [

{

"id": "startTime",

"name": "开始时间",

"type": "date",

"required": true,

"placeholder": "empty"

},

{

"id": "endTime",

"name": "结束时间",

"type": "date",

"required": true,

"placeholder": "empty"

},

{

"id": "reason",

"name": "请假原因",

"type": "text",

"required": true,

"placeholder": "empty"

}

],

"outcomes": [

{

"id": "sendToParent",

"name": "发给上级"

},

{

"id": "sendToHr",

"name": "发给人事"

}

]

}

FormViewDelegate定义

使用runtimeService.getStartFormModel获取开始表单

因为表单数据实际上是存在流程variables里的,所以使用execution.getVariable()获取表单值(不过有个FormField.getValue()方法,按照常理来说,是用来获取值的,但是实际上并没有,这个不知道是否版本问题,还是其他用途的)

package com.baison.bap.flowable.delegate;

import com.baison.bap.util.SpringUtil;

import org.flowable.engine.RuntimeService;

import org.flowable.engine.delegate.DelegateExecution;

import org.flowable.engine.delegate.JavaDelegate;

import org.flowable.form.api.FormInfo;

import org.flowable.form.model.FormField;

import org.flowable.form.model.SimpleFormModel;

import java.util.List;

public class FormViewDelegate implements JavaDelegate {

private RuntimeService runtimeService = SpringUtil.getBean(RuntimeService.class);

@Override

public void execute(DelegateExecution execution) {

FormInfo info = runtimeService.getStartFormModel(execution.getProcessDefinitionId(), execution.getProcessInstanceId());

SimpleFormModel sfm = (SimpleFormModel) info.getFormModel();

List fields = sfm.getFields();

for (FormField ff : fields) {

System.out.println();

System.out.println("id: " + ff.getId());

System.out.println("name: " + ff.getName());

System.out.println("type: " + ff.getType());

System.out.println("placeholder: " + ff.getPlaceholder());

System.out.println("value: " + ff.getValue());

System.out.println("value from variable: " + execution.getVariable(ff.getId()));

System.out.println();

}

}

}

获取流程表单

流程中的表单有两种:流程开始表单和流程中表单

查看是否有表单

// 流程开始表单

ProcessDefinition.hasStartFormKey();

// 流程中表单

Task.getFormKey();

获取开始流程表单

ProcessDefinition pd = repositoryService.createProcessDefinitionQuery().processDefinitionKey(code).latestVersion().singleResult();

StartFormData form = formService.getStartFormData(pd.getId());

FormInfo info = formRepositoryService.getFormModelByKey(form.getFormKey());

info.getFormModel();

获取流程中用户需要填写的表单

TaskFormData form = formService.getTaskFormData(taskId);

填写表单

runtimeService.startProcessInstanceWithForm和formService.submitStartFormData都能填写完成表单并开始流程

也就是说其实表单填写的数据都是放在variables里的

开始表单

ProcessDefinition pd = repositoryService.createProcessDefinitionQuery().processDefinitionKey("formRequest").latestVersion().singleResult();

Map properties = new HashMap<>();

properties.put("startTime", "2018-12-14");

properties.put("endTime", "2018-12-20");

properties.put("reason", "回家");

// ProcessInstance pi = runtimeService.startProcessInstanceWithForm(pd.getId(), "sendToParent", properties, null);

ProcessInstance pi = formService.submitStartFormData(pd.getId(), UUID.randomUUID().toString(), properties);

流程中表单

TaskService.completeTaskWithForm(String taskId, String formDefinitionId, String outcome, Map variables)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值