1. 程式人生 > 實用技巧 >關於兩種常用的監聽

關於兩種常用的監聽

FlowAble監聽的兩個監聽taskListener 和 executionListener

注意如果想要讓flowable或activiti能獲取到service 那麼最好在呼叫的service 用 Component 註解 並指定名稱

例如:@Component("sequenceFlowListener") 

1、TaskListener  主要是監聽usertask的情況,監聽事件event有4種:

create 建立

assignment 分配人

complete 完成

delete 刪除

程式碼:
@Service
public class CountersignTaskListener implements TaskListener{
    @Override
    public void notify(DelegateTask delegateTask) {
        System.out.println(
"aaaaaaaaaaaaaaaaaaaaaaaaaa"); System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaaa"); } } xml: <userTask id="USERTASK" name="USERTASK" > <extensionElements> <activiti:taskListener event="create" delegateExpression="${sequenceFlowListener}"/> </extensionElements> </userTask> 2
、ExecutionListener 主要是監聽 sequenceFlow的監聽器,監聽事件有3種 start 開始 take 啟用 end 結束 程式碼如下; @Component("sequenceFlowListener") public class SequenceFlowListener implements ExecutionListener { @Override public void notify(DelegateExecution execution) { System.out.println("aaaaaaaaaaaaaa"); execution.setVariable(
"審批人","111"); System.out.println("aaaaaaaaaaaaaa"); } } xml: <sequenceFlow id="sequenceFlow-b619e9a1-9e15-4ada-9bf6-54e0fcf7f6c8" name="條件1" sourceRef="gateWay-9134083e-a2a3-4021-9628-f478602c5933" targetRef="userTask-counterSign-0ae5c7c5-b282-4e4d-b8dd-b3d5fe623583"> <extensionElements> <flowable:executionListener event="take" delegateExpression="${sequenceFlowListener}"></flowable:executionListener> </extensionElements> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${conditionService.checkCondition(1,'userTask-counterSign-0ae5c7c5-b282-4e4d-b8dd-b3d5fe623583',execution)}]]></conditionExpression> </sequenceFlow>