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

  • 相关阅读:
    java注解,通过反射解析注解,模仿hibernate,获取sql语句。
    Eclipse/Myeclipse中查看和调试JDK源代码的方法
    TCP为什么会出现 RST
    《浅谈F5健康检查常用的几种方式》—那些你应该知道的知识(二)
    负载均衡服务TCP端口健康检查成功,为什么在后端业务日志中出现网络连接异常信息?
    haproxy的丰富特性简介
    健康检查概述
    firewall防火墙常用操作
    gitlab修改默认端口
    vim脚本判断操作系统
  • 原文地址:https://www.cnblogs.com/liaojie970/p/9055072.html
Copyright © 2011-2022 走看看