zoukankan      html  css  js  c++  java
  • activiti实战系列之动态表单 formService 自定义变量类型

    目前Activiti默认支持的类型有String,long,enum,date,boolean,collection

    要自定义字段类型,首先需要表单类型解析类

    /**
     * @Author:LJ
     * @Description: activiti Javascript类型表单字段
     * @Date: 2018/5/17
     * @Modified By:
     */
    public class JavascriptFormType extends AbstractFormType {
        /**
         * 把表单中的值转换为实际的对象
         * @param propertyValue
         * @return
         */
        @Override
        public Object convertFormValueToModelValue(String propertyValue) {
            return propertyValue;
        }
    
        /**
         * 把实际对象的值转换为表单中的值
         * @param modelValue
         * @return
         */
        @Override
        public String convertModelValueToFormValue(Object modelValue) {
            return (String) modelValue;
        }
    
        /**
         * 定义表单类型的标识符
         *
         * @return
         */
        @Override
        public String getName() {
            return "javascript";
        }
    }

    第二、在流程引擎中注册解析类

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
                    http://www.springframework.org/schema/beans/spring-beans.xsd">
    
        <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
    .... <!-- 自定义表单字段类型 --> <property name="customFormTypes"> <list> <bean class="me.kafeitu.activiti.form.JavascriptFormType" /> </list> </property> </bean> </beans>

     扩展:SpringBoot方式注册解析

    package com.example.demo.config;
    
    import com.example.demo.config.formType.JavascriptFormType;
    import org.activiti.engine.form.AbstractFormType;
    import org.activiti.spring.SpringProcessEngineConfiguration;
    import org.springframework.beans.BeansException;
    import org.springframework.beans.factory.config.BeanPostProcessor;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
    import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
    
    import java.util.Arrays;
    import java.util.List;
    
    /**
     * @Author:LJ
     * @Description:
     * @Date: 2018/3/21
     * @Modified By:
     */
    @Configuration
    public class ApplicationConfig extends WebMvcConfigurerAdapter {/**
         * 方式一
         *@Author LJ
        */
        @Bean
        public BeanPostProcessor activitiConfigurer() {
            return new BeanPostProcessor() {
                @Override
                public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
                    if (bean instanceof SpringProcessEngineConfiguration) {
                        List<AbstractFormType> customFormTypes = Arrays.<AbstractFormType>asList(new JavascriptFormType());
                        ((SpringProcessEngineConfiguration)bean).setCustomFormTypes(customFormTypes);
                    }
                    return bean;
                }
                @Override
                public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
                    return bean;
                }
            };
    
        }
    }

    参考:

    How to declare an Activiti custom FormType in a Spring Boot application

  • 相关阅读:
    Learning NFS/NIS 2nd 读书笔记-Chapter3 NIS Operation
    Linux Enterprise Cluster Notes Ch11 LVS Introduction Theory
    Linux Enterprise Cluster NOtes Ch7 A Sample HA config
    Linux Enterprise Cluster Notes Ch10 build a Linux cluster
    Linux Enterprise Cluster NOtes Ch8 Heartbeat配置和维护
    当被监控的应用发生问题时,heartbeat会failover么?
    Linux Enterprise Cluster NOtes Ch9 Stonith and IPFail
    Linux Enterprise Cluster NOtes Ch6 Heartbeat介绍和原理
    客户端不支持javascript怎么办
    js 返回对象|js返回多个值的方法|js如何返回多个值
  • 原文地址:https://www.cnblogs.com/liaojie970/p/9055072.html
Copyright © 2011-2022 走看看