之前实现了activiti工作流的动态表单功能,接下来准备实现activiti的外置表单功能,并且外置表单可以在线编辑。
activiti工作流在线表单设计功能实现可以分为2个部分:
1.在线表单设计功能。
2.表单与activiti工作流关联起来。
第一部分,在线表单设计功能可以使用ueditor 的插件WEB表单设计器实现。
第二部分,可以使用activiti工作流的外置表单 原理关联 WEB表单设计器 设计的表单。
主要难点在实现第一部分,具体效果图如下:
相关所有实现代码:
list.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
在线表单列表
<%@include file="/common/base.jsp" %>
表单名称
描述
设计者
日期
是否启用
操作
add.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.springframework.context.ApplicationContext" %>
<%@page import="com.jy.service.onlineform.OnlineFormService" %>
<%
ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
OnlineFormService onlineFormService = (OnlineFormService)ctx.getBean("onlineFormService");
String bizId = request.getParameter("bizId");
if(bizId != null && !bizId.equals("")){
request.setAttribute("of", onlineFormService.getEntityById(bizId));
}
%>
新增文档
<%@include file="/common/base.jsp" %>
design.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.springframework.context.ApplicationContext" %>
<%@page import="com.jy.service.onlineform.OnlineFormService" %>
<%
ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
OnlineFormService onlineFormService = (OnlineFormService)ctx.getBean("onlineFormService");
String bizId = request.getParameter("bizId");
if(bizId != null && !bizId.equals("")){
request.setAttribute("of", onlineFormService.getEntityById(bizId));
}
%>
设计表单
<%@include file="/common/base.jsp" %>
preview.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import= "com.jy.common.utils.UeditorTools "%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
新增文档
<%@include file="/common/base.jsp" %>
预览表单 如无问题请保存你的设计
<%= UeditorTools.formatStr(request.getParameter("html"))%>
OnlineFormController.java
package com.jy.controller.onlineform;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.jy.common.ajax.AjaxRes;
import com.jy.common.utils.base.Const;
import com.jy.common.utils.base.Tools;
import com.jy.common.utils.security.AccountShiroUtil;
import com.jy.controller.base.BaseController;
import com.jy.entity.onlineform.OnlineForm;
import com.jy.service.onlineform.OnlineFormService;
@Controller
@RequestMapping("/OnlineFormController/")
public class OnlineFormController extends BaseController
OnlineFormMapper.xml
insert into online_form(id,key,descr,enabled,addUserId,addtime)
values(#{id},#{key},#{descr},#{enabled},#{addUserId},sysdate)
update online_form set key=#{key},descr=#{descr},enabled=#{enabled}
,modUserId=#{modUserId},modtime=sysdate
where id=#{id}
update online_form set html=#{html,jdbcType=CLOB}
,modUserId=#{modUserId},modtime=sysdate
where id=#{id}
delete from online_form where id=#{id}
看到一直有人问UeditorTools这个类。其实挺简单的,我找了下,下面贴出来了。
com.jy.common.utils.UeditorTools
package com.jy.common.utils;
public class UeditorTools {
/**
* 去掉分界符 {|- 和 -|}
* @param str
* @return
*/
public static String formatStr(String str){
str = replaceAll(str,"{|-","");
str = replaceAll(str,"-|}","");
return str;
}
public static String replaceAll(String strAll,String oldStr,String newStr){
return strAll.replaceAll(escapeExprSpecialWord(oldStr), "");
}
/**
* 转义正则特殊字符 ($()*+.[]?\^{},|)
* @param keyword
* @return
*/
public static String escapeExprSpecialWord(String keyword) {
if (keyword != null && !keyword.equals("")) {
String[] fbsArr = { "\\", "$", "(", ")", "*", "+", ".", "[", "]", "?", "^", "{", "}", "|" };
for (String key : fbsArr) {
if (keyword.contains(key)) {
keyword = keyword.replace(key, "\\" + key);
}
}
}
return keyword;
}
}