How to get enum values in activiti and what is return type of getType() of FormProperty in activiti?

StackOverflow https://stackoverflow.com/questions/17610976

  •  02-06-2022
  •  | 
  •  

I want to get the values of the enum property.

In activiti 5.13 userguide,

the enumeration values are accessible with formProperty.getType().getInformation("values")

In activiti docs,return type of getType() is FormType. But in my code getType() return type is String. So i couldn't call FormType's getInformation() method.

When i am using formProperty.getType().getInformation("values"), i got the following error.

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

How could i get the values of enum?

有帮助吗?

解决方案

<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>

Consider above user Task and You can do like this

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

    }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top