gpt4 book ai didi

grails - 如何在activiti中获取枚举值以及activiti中FormProperty的getType()的返回类型是什么?

转载 作者:行者123 更新时间:2023-12-01 15:30:11 25 4
gpt4 key购买 nike

我想获取枚举属性的值。

在 activiti 5.13 用户指南中,

可以使用 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'.

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

最佳答案

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

}

关于grails - 如何在activiti中获取枚举值以及activiti中FormProperty的getType()的返回类型是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17610976/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com