2013-07-12 4 views
3

Я хочу получить значения свойства enum.
Как получить значения enum в activiti и что такое тип возврата getType() FormProperty в activiti?

В Activiti 5.13 UserGuide,

значения перечисления доступны с formProperty.getType().getInformation("values")

В Activiti документы, возврат тип GetType() является FormType. Но в моем коде getType() возвращает тип String. Поэтому я не мог вызвать метод getInformation() FormType.

Когда я использую formProperty.getType().getInformation("values"), я получил следующую ошибку.

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

Как я могу получить значения перечисления?

+0

Это выглядит странно. Этот код shoul работает, может быть, вы случайно вызываете formProperty.getType(). GetName(), который возвращает строку «enum» для EnumFormType – ATMTA

+0

Привет, Atmta, Спасибо за ваш ответ. Ya этот код правильный. Но я не знаю, почему он не работает. для меня 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() 
      } 
     } 

    } 

 Смежные вопросы

  • Нет связанных вопросов^_^