activiti實戰讀書筆記——第十章 之 子流程


一、開始事件中運用了兩個自定義的表單類型bigtext和double html

<startEvent id="startevent1" name="startevent1" activiti:initiator="applyUserId">
      <extensionElements>
        <activiti:formProperty id="dueDate" name="到貨期限" type="date" datePattern="yyyy-MM-dd" required="true"></activiti:formProperty>
        <activiti:formProperty id="listing" name="物品清單" type="bigtext" required="true"></activiti:formProperty>
        <activiti:formProperty id="amountMoney" name="總金額" type="double" required="true"></activiti:formProperty>
      </extensionElements>
    </startEvent>



須要編寫表單類型類並加入到processEngineConfiguration中:

public class BigtextFormType extends StringFormType {

	@Override
	public String getName(){
		return "bigtext";
	}

}
public class DoubleFormType extends AbstractFormType {

	@Override
	public String getName() {
		return "double";
	}

	@Override
	public Object convertFormValueToModelValue(String formValue) {
		return new Double(formValue);
	}

	@Override
	public String convertModelValueToFormValue(Object modelValue) {
		return Objects.toString(modelValue);
	}

}



List<AbstractFormType> customFormTypes = new ArrayList<AbstractFormType>();
		customFormTypes.add(new BigtextFormType());
		customFormTypes.add(new DoubleFormType());
		processEngineConfiguration.setCustomFormTypes(customFormTypes);



並在start-process-form.jsp和task-form.jsp中加入相關類型的顯示處理:

<%-- 文本或者數字類型 --%>
				<c:if test="${fp.type.name == 'string' || fp.type.name == 'long' || fp.type.name == 'double'}">
					<label class="control-label" for="${fp.id}">${fp.name}:</label>
					<div class="controls">
						<input type="text" id="${fp.id}" name="${fp.id}" data-type="${fp.type.name}" value="" />
					</div>
				</c:if>
				
				<%-- 大文本 --%>
				<c:if test="${fp.type.name == 'bigtext'}">
					<label class="control-label" for="${fp.id}">${fp.name}:</label>
					<div class="controls">
						<textarea id="${fp.id}" name="${fp.id}" data-type="${fp.type.name}" ${required}></textarea>
					</div>
				</c:if>



二、在指向付費子流程的sequenceFlow中添加了監聽器用於設置usage變量:

<sequenceFlow id="flow22" name="進入付費子流程" sourceRef="contactSupplier" targetRef="subprocessPay">
      <extensionElements>
        <activiti:executionListener event="take" expression="${execution.setVariable('usage', listing)}"></activiti:executionListener>
      </extensionElements>
    </sequenceFlow>



三、子流程使用標籤subProcess,內部也是一個完成的流程。在其中除了空結束事件(正常結束)外還定義了兩個異常結束事件
<endEvent id="errorendevent1" name="TerminateEndEvent">
        <errorEventDefinition errorRef="PAYMENT_REJECT"></errorEventDefinition>
      </endEvent>

      <endEvent id="errorendevent2" name="End">
        <errorEventDefinition errorRef="PAYMENT_REJECT"></errorEventDefinition>
      </endEvent>

外部與異常邊界事件關聯 java

<boundaryEvent id="boundaryerror1" name="Error" attachedToRef="subprocessPay">
      <errorEventDefinition errorRef="PAYMENT_REJECT"></errorEventDefinition>
    </boundaryEvent>



四、act_ru_execution表爲運行實例表

運行流程後查看此表有兩條流程實例ID相同的記錄,一個ID與流程實例ID相同時主流程,另外一個爲子流程,它的parent_id_不空,指向主流程的實例ID。 express

五、act_hi_procinst表爲歷史流程實例表 app

其中只有一條關於主流程的記錄,而無子流程記錄。 jsp

六、在子流程中的一些用戶任務使用了amountMoney變量,而在子流程中並未設置此變量。查看act_hi_varinst表,子流程能夠共享主流程的全部變量,並且子流程在獲取數據時使用主流程的執行實例ID(parent_id_字段)查詢變量。 ide

相關文章
相關標籤/搜索