2013-07-12 71 views
3

我想獲取枚舉屬性的值。
如何在activiti中獲取枚舉值以及Activiti中FormProperty的getType()的返回類型是什麼?

Activiti中5.13 userguide,

枚舉值與formProperty.getType().getInformation("values")

Activiti中文檔訪問,(的getType的返回類型)是FormType。但在我的代碼getType()返回類型是String。所以我無法調用FormType的getInformation()方法。

當我使用formProperty.getType().getInformation("values")時,出現以下錯誤。

Cannot cast object 'enum' with class 'java.lang.String' to class 'org.activiti.engine.form.FormType'. 

我怎麼能得到enum的值?

+0

這看起來很奇怪。此代碼工作,可能是你無意中調用formProperty.getType()。getName()返回EnumFormType的「枚舉」字符串 – ATMTA

+0

嗨Atmta,感謝您的回覆。雅這個代碼是正確的。但我不知道爲什麼它不工作。對於我來說,formProperty.getType()返回枚舉。 – Visme

+0

你可以嘗試調試它嗎? – ATMTA

回答

1
<userTask id="handleRequest" name="Handle vacation request" activiti:candidateGroups="management"> 
    <documentation>${employeeName} would like to take ${numberOfDays} day(s) of vacation (Motivation: ${vacationMotivation}).</documentation> 
    <extensionElements> 
    <activiti:formProperty id="vacationApproved" name="Do you approve this vacation" type="enum" required="true"> 
     <activiti:value id="true" name="Approve"></activiti:value> 
     <activiti:value id="false" name="Reject"></activiti:value> 
    </activiti:formProperty> 
    <activiti:formProperty id="managerMotivation" name="Motivation" type="string"></activiti:formProperty> 
    </extensionElements> 
</userTask> 

考慮上述用戶的任務,你可以這樣做

//passing Task Id and Process definition Id 

    def getFormForTask(taskId,pdId) { 

     RepositoryService repositoryService =processEngine.getRepositoryService() 

     // getting model 
     BpmnModel model = repositoryService.getBpmnModel(pdId); 

     // getting list process from model including tasks 
     List<Process> processes = model.getProcesses() 

     List<FormProperty> taskFormPropertyList =[] 

     for(Process proc : processes) { 
      for(Object obj : proc.getFlowElements()) { 
       // need form Property only for User Task 
       if(obj instanceof UserTask) { 
        UserTask userTask = (UserTask)obj 
        if(userTask.getId() == taskId){ 
        // getting list of Form Property from task that matches taskId 
         taskFormPropertyList = userTask.getFormProperties() 
        } 
       } 

      } 
     } 

    // loop through from Property 
     taskFormPropertyList.each { 
      // getFormValues() returns Property values for the form Property (like enum) 
      def fvlist = it.getFormValues() 
      fvlist.each { 
       // prints id, in this case true and false 
       println it.getId() 

       // prints name, in this case Approve and Reject 
       println it.getName() 
      } 
     } 

    }