3

我想获取枚举属性的值。

在 activiti 5.13 用户指南中,

枚举值可以通过formProperty.getType().getInformation("values")

在 activiti 文档中,getType() 的返回类型是 FormType。但在我的代码中 getType() 返回类型是字符串。所以我不能调用 FormType 的 getInformation() 方法。

当我使用时formProperty.getType().getInformation("values"),出现以下错误。

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

我怎样才能得到枚举的值?

4

1 回答 1

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()
            }
        }

    }
于 2013-07-12T11:55:18.187 回答