`

十八、自定义VariableResolver

 
阅读更多

<decision name="decision1" expression="#{days gt 10 ? '提交给李四审批':'提交给王五审批'}">

在上面中days变量默认是从ContextInstance中读取,我们也可以自定义获取变量的规则。

 

public class MyVariableResolver extends JbpmVariableResolver {
   
    @Override
    public Object resolveVariable(String name) throws ELException {
        if (name.startsWith("sys_")) {
           
            ExecutionContext executionContext = ExecutionContext.currentExecutionContext();
            long docId = (Long) executionContext.getContextInstance().getVariable("documentId");
            Document document = (Document) executionContext.getJbpmContext().getSession().load(
                Document.class, docId);
            String newName = name.substring(4);
            //先随便这样写着,可以使用beanutils工具类
            if (newName.equals("days")) {
                int days = document.getDays();
               
                return days;
            } else {
                return null;
            }
           
        } else {
            return super.resolveVariable(name);
        }
    }
   
}

 

修改jbpm.cfg.xml文件

 

<jbpm-configuration>

   <bean   name="jbpm.variable.resolver"     class="com.ygtim.domain.MyVariableResolver"                    singleton="true" />
</jbpm-configuration>

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics