如何从执行侦听器读取表单数据
How to read Form data from Execution listener
我正在与 activiti-5.21.0
合作。我有
我创建了具有用户任务的 myProcess.bpmn
。用户任务有一个表单。当此表单将由受让人用户提交时,即 "kermit" 那么如何读取以 java class?
中的表单提交的数据
myProcess.bpmn
型号:
<process id="myProcess" name="My process" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<userTask id="usertask1" name="User Task" activiti:assignee="kermit">
<extensionElements>
<activiti:formProperty id="name" name="Name" type="string" required="true"></activiti:formProperty>
<activiti:formProperty id="comment" name="comment" type="string"></activiti:formProperty>
<activiti:executionListener event="start" class="com.demo.ActivitiForm"></activiti:executionListener>
</extensionElements>
</userTask>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
<sequenceFlow id="flow2" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>
</process>
如果您想从任何地方访问变量(不考虑流)。使用流程实例 ID,你可以试试这个 -
Map<String, Object> variables = runtimeService.getVariables(processInstanceId);
String name = (String)variable.get("name");
String comment = (String)variable.get("comment");
更改执行 event="end"
然后试试这个 -
package com.demo;
//all import statement
public class ActivitiForm implements ExecutionListener {
public void notify(ExecutionListenerExecution execution) throws Exception {
String name = (String) execution.getVariable("name");
String comment = (String) execution.getVariable("comment");
System.out.println(name + " made the following comment: " + comment); //see this sys.out in your admin log.
}
}
我正在与 activiti-5.21.0
合作。我有
我创建了具有用户任务的 myProcess.bpmn
。用户任务有一个表单。当此表单将由受让人用户提交时,即 "kermit" 那么如何读取以 java class?
myProcess.bpmn
型号:
<process id="myProcess" name="My process" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<userTask id="usertask1" name="User Task" activiti:assignee="kermit">
<extensionElements>
<activiti:formProperty id="name" name="Name" type="string" required="true"></activiti:formProperty>
<activiti:formProperty id="comment" name="comment" type="string"></activiti:formProperty>
<activiti:executionListener event="start" class="com.demo.ActivitiForm"></activiti:executionListener>
</extensionElements>
</userTask>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
<sequenceFlow id="flow2" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>
</process>
如果您想从任何地方访问变量(不考虑流)。使用流程实例 ID,你可以试试这个 -
Map<String, Object> variables = runtimeService.getVariables(processInstanceId);
String name = (String)variable.get("name");
String comment = (String)variable.get("comment");
更改执行 event="end"
然后试试这个 -
package com.demo;
//all import statement
public class ActivitiForm implements ExecutionListener {
public void notify(ExecutionListenerExecution execution) throws Exception {
String name = (String) execution.getVariable("name");
String comment = (String) execution.getVariable("comment");
System.out.println(name + " made the following comment: " + comment); //see this sys.out in your admin log.
}
}