• 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

  • 相关阅读:
    Jquery操作select
    Session在类库中的使用
    从一个表取数据更新另一个表的信息
    判断数据库表中是否存在某个字段
    .net项目中上传的图片或者文件太大 无法上传
    计算机中丢失 msvcr110.dlll
    Ubuntu搭建FTP server
    Linux常用命令集
    系统清理篇
    ubuntu安装 ssh server
  • 原文地址:https://www.cnblogs.com/liaojie970/p/9055072.html
Copyright © 2020-2023  润新知