2016-06-16 66 views
0

我試圖設置org.activiti.engine.impl.bpmn.listener.ScriptTaskListenerautoStoreVariables字段。如何在activiti中設置布爾型字段

這是包含taskListeneruserTask

<userTask id="WorkJob.task" name="WorkJob.task" activiti:assignee="${assignee}" activiti:dueDate="${dueDate}"> 
    <extensionElements> 
     <activiti:taskListener event="create" class="org.activiti.engine.impl.bpmn.listener.ScriptTaskListener" > 
      <activiti:field name="autoStoreVariables" expression="${true}"/> 
      <activiti:field name="script" stringValue="${out:print('hello world')}"/> 
      <activiti:field name="language" stringValue="juel" /> 
     </activiti:taskListener> 
    </extensionElements> 
</userTask> 

得到以下錯誤:

org.activiti.engine.ActivitiIllegalArgumentException: Incompatible type set on field declaration 'autoStoreVariables' for class org.activiti.engine.impl.bpmn.listener.ScriptTaskListener. Declared value has type org.activiti.engine.impl.el.JuelExpression, while expecting boolean

我嘗試沒有成功如下:

<activiti:field name="autoStoreVariables" booleanValue="true"/> 

<activiti:field name="autoStoreVariables" stringValue="true"/> 

<activiti:field name="autoStoreVariables" expression="true"/> 

什麼是設置boolean場的正確方法是什麼?

回答

1

Accordint到Activiti的用戶指南Field Injection

It’s possible to inject values into the fields of the delegated classes. The following types of injection are supported:

  • Fixed string values
  • Expressions

看起來是不可能直接注入布爾值。我認爲您的解決方案是延長ScriptTaskListener,例如

public class CustomScriptTaskListener extends ScriptTaskListener { 

    private Expression autoStoreVariablesExp; 

    public void setAutoStoreVariablesExp(Expression autoStoreVariablesExp) { 
     this.autoStoreVariablesExp = autoStoreVariablesExp; 
    } 

    @Override 
    public void notify(DelegateTask delegateTask) { 
     autoStoreVariables = Boolean.TRUE.equals(autoStoreVariablesExp.getValue(delegateTask)); 

     super.notify(delegateTask); 
    } 
} 

並注入價值<activiti:field name="autoStoreVariablesExp" expression="${true}"/>

相關問題