日期:2014-05-16  浏览次数:20376 次

jbpm]在JSP页面中显示JBPM流程图
[jbpm]在JSP页面中显示JBPM流程图2008-07-10 14:20下载jbpm-starters-kit-3.1.x工具包。在包中有. java文件,\jbpm.3\src\java.webapp\org\jbpm\webapp\tag\ProcessImageTag.java与 他的\WEB-INF\jbpm.tld,还有文件\jbpm.3\src\java.webapp\org\jbpm\webapp\servlet\ ProcessImageServlet.java,在JBPM的例子里,这三个文件共同完成JBPM流程图的显示。

要使两个文件发生作用,必须得在web.xml里配置,配置方法:
<!-- jBPM FileServlet -->
<servlet>
    <servlet-name>ProcessImageServlet</servlet-name>
    <servlet-class>org.jbpm.webapp.servlet.ProcessImageServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>ProcessImageServlet</servlet-name>
    <url-pattern>/processimage</url-pattern>
</servlet-mapping>

在页面中使用:<jbpm:processimage task="${taskBean.taskInstanceId}"/> 就会把流程图显示在当前位置。

在实际环境中可能会出现的问题与必要的修改

问题一
如果你是用spring整合的jbpm,那么在两个类里的取JbpmContext方法会出错。
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext(); //这个是会出问题的。
修改:

1).ProcessImageTag.java的private void initialize()方法里。
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(pageContext.getServletContext());
      JbpmTemplate jbpmTemplate = (JbpmTemplate) wac.getBean("jbpmTemplate");
      jbpmTemplate.execute(new JbpmCallback() {
          public Object doInJbpm(JbpmContext context) {
              if (taskInstanceId > 0) {
                  TaskInstance taskInstance = context.getTaskMgmtSession().loadTaskInstance(taskInstanceId);
                  currentToken = taskInstance.getToken();
              }
              else
              {
                  if (tokenInstanceId > 0)
                      currentToken = context.getGraphSession().loadToken(tokenInstanceId);
              }
              return null;
          }
      });

2).
public class ProcessImageServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    private ProcessDefinition processDefinition;
    private byte[] bytes;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        final long processDefinitionId = Long.parseLong( request.getParameter( "definitionId" ) );

        WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession().getServletContext());
        JbpmTemplate jbpmTemplate = (JbpmTemplate) wac.getBean("jbpmTemplate");
        jbpmTemplate.execute(new JbpmCallback() {
        &nbs