b/s下显示图片需对jbpm提供的标签改写,通过taskInstanceId来显示当前节点下的图片,在开始节点下无taskInstanceId所以无法显示图片 。
1 action转到显示图片页面
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.shane.commons.core.web.StrutsAction;
public class WorkflowAction extends StrutsAction {
public ActionForward viewImage(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
long taskInstanceId =Long.parseLong(request.getParameter("id"));
request.setAttribute("taskInstanceId", taskInstanceId);
return mapping.findForward("view_image");
}
}
2 view_image.jsp流程图片显示页面,使用改写后的jbpm标签。
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<%@taglib uri="/WEB-INF/jbpm.tld" prefix="jbpm"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>查看流程的图片</title>
</head>
<body>
<center>
<TABLE class="tableEdit" border="0" cellspacing="1" cellpadding="0" style="width:580px;">
<TBODY>
<TR>
<!-- 这里是添加、编辑界面的标题 -->
<td align="center" class="tdEditTitle">
</TD>
</TR>
<TR>
<td>
<!-- 主输入域开始 -->
<jbpm:processimage task="${taskInstanceId}"/>
<!-- 主输入域结束 -->
</td>
</TR>
</TBODY>
</TABLE>
<TABLE>
<TR align="center">
<TD colspan="3" bgcolor="#EFF3F7">
<input type="button" class="MyButton"
value="关闭窗口" onclick="window.close()">
</TD>
</TR>
</TABLE>
</center>
</body>
</html>
3 改写的标签类继承spring的RequestContextAwareTag类,支持 servlet方式。
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jbpm.webapp.tag;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.jbpm.graph.exe.Token;
import org.springframework.web.servlet.tags.RequestContextAwareTag;
import com.shane.components.xmlservice.XMLService;
import com.shane.security.service.CurrentNodeImageManager;
public class ProcessImageTag extends RequestContextAwareTag {
private XMLService xmlService = new XMLService("URL");
private static final long serialVersionUID = 1L;
private long taskInstanceId = -1;
private long tokenInstanceId = -1;
private byte[] gpdBytes = null;
private byte[] imageBytes = null;
static String currentTokenColor = "red";
static String childTokenColor = "blue";
static String tokenNameColor = "blue";
private CurrentNodeImageManager currentNodeImageManager;
public void release() {
taskInstanceId = -1;
gpdBytes = null;
imageBytes = null;
// currentToken = null;
}
public int doEndTag() throws JspException {
try {
//initialize();
if(taskInstanceId!=0) {
retrieveByteArrays();
if (gpdBytes != null && imageBytes != null) {
writeTable();
}
}
} catch (IOException e) {
e.printStackTrace();
throw new JspException("table couldn't be displayed", e);
} catch (DocumentException e) {
e.printStackTrace();
throw new JspException("table couldn't be displayed", e);
}
release();
return EVAL_PAGE;
}
private void retrieveByteArrays() {
try {
// FileDefinition fileDefinition = processDefinition.getFileDefinition();
gpdBytes = currentNodeImageManager.getGpdBytes(taskInstanceId);
imageBytes = currentNodeImageManager.getImageBytes(taskInstanceId);
} catch (Exception e) {
e.printStackTrace();
}
}
private void writeTable() throws IO