Display the JBPM flowchart on the JSP page

Source: Internet
Author: User
Tags jbpm

To display the JBPM flowchart on the JSP page, download the jbpm-starters-kit-3.1.x toolkit first. There is a. java file in the package,

\ Jbpm.3 \ src \ java. webapp \ org \ jbpm \ webapp \ tag \ ProcessImageTag. java with his \ WEB-INF \ jbpm. tld, There are files

\ Jbpm.3 \ src \ java. webapp \ org \ jbpm \ webapp \ servlet \ ProcessImageServlet. java. In the JBPM example, these three files are used together to display the JBPM flowchart.

To make the two files work, you must configure them in web. xml. configuration method:

 
 
  1. <!-- jBPM FileServlet -->   
  2. <servlet>   
  3.     <servlet-name>ProcessImageServlet</servlet-name>   
  4.     <servlet-class>org.jbpm.webapp.servlet.ProcessImageServlet</servlet-class>   
  5. </servlet>   
  6. <servlet-mapping>   
  7.     <servlet-name>ProcessImageServlet</servlet-name>   
  8.     <url-pattern>/processimage</url-pattern>   
  9. </servlet-mapping>   

On the page, use <jbpm: processimage task = "$ {taskBean. taskInstanceId}"/> to display the flowchart at the current position.

Problems that may occur in the actual environment and necessary modifications

Question 1

If you use spring-integrated jbpm, The JbpmContext method in the two classes will fail.

JbpmContext jbpmContext = JbpmContext. getCurrentJbpmContext (); // This will cause problems.

Modify:

1. In the private void initialize () method of ProcessImageTag. java.

 
 
  1. WebApplicationContext wac = WebApplicationContextUtils.
    getRequiredWebApplicationContext(pageContext.getServletContext());   
  2.       JbpmTemplate jbpmTemplate = (JbpmTemplate) wac.getBean("jbpmTemplate");   
  3.       jbpmTemplate.execute(new JbpmCallback() {   
  4.           public Object doInJbpm(JbpmContext context) {   
  5.               if (taskInstanceId > 0) {   
  6.                   TaskInstance taskInstance = context.getTaskMgmtSession().loadTaskInstance(taskInstanceId);   
  7.                   currentToken = taskInstance.getToken();   
  8.               }   
  9.               else   
  10.               {   
  11.                   if (tokenInstanceId > 0)   
  12.                       currentToken = context.getGraphSession().loadToken(tokenInstanceId);   
  13.               }   
  14.               return null;   
  15.           }   
  16.       });   
 
 

  1. public class ProcessImageServlet extends HttpServlet {   
  2.     private static final long serialVersionUID = 1L;   
  3.     private ProcessDefinition processDefinition;   
  4.     private byte[] bytes;   
  5.  
  6.     protected void doGet(HttpServletRequest request, 
    HttpServletResponse response) throws ServletException, IOException {   
  7.         final long processDefinitionId = Long.parseLong( request.getParameter( "definitionId" ) );   
  8.  
  9.         WebApplicationContext wac = WebApplicationContextUtils.
    getRequiredWebApplicationContext(request.getSession().getServletContext());   
  10.         JbpmTemplate jbpmTemplate = (JbpmTemplate) wac.getBean("jbpmTemplate");   
  11.         jbpmTemplate.execute(new JbpmCallback() {   
  12.             public Object doInJbpm(JbpmContext context) {   
  13.                 processDefinition = context.getGraphSession().loadProcessDefinition(processDefinitionId);   
  14.                 bytes = processDefinition.getFileDefinition().getBytes("processimage.jpg");   
  15.                 return null;   
  16.             }   
  17.         });   
  18.  
  19.         OutputStream out = response.getOutputStream();   
  20.         out.write(bytes);   
  21.         out.flush();   
  22.     }   
  23. }   

Question 2

If your process uses Chinese characters and the database character set is UTF-8, the correct UTF-8 content in the database may also be garbled. For example, gpd. xml in my database

Error class: ProcessImageTag. java

Error row: result [0] = Integer. valueOf (node. attribute ("x"). getValue ());

If this is an nullpoint error, it is because the characters in the context Element root are garbled.

Modify:

Original code: Element rootDiagramElement = incluenthelper. parseText (new String (gpdBytes). getRootElement ();

After modification: Element rootDiagramElement = incluenthelper. parseText (new String (gpdBytes, "UTF-8"). getRootElement ();

Note: <jbpm: processimage task = "$ {taskBean. taskInstanceId}"/> displays images based on the current path. Style = "background-image: url (processimage? DefinitionId = 1) ", that is, when the page is: http: // localhost/jbpm/workflow/showTaskInstance. in jsp, the URL of the access flowchart is http: // localhost/jbpm/workflow/processimage? DefinitionId = 1. The address is incorrect. The actual address is: http: // localhost/jbpm/processimage? DefinitionId = 1. to display the information correctly, modify ProcessImageTag. java.

Original code: background-image: url ("+ imageLink + ");

After modification: background-image: url ("+ (HttpServletRequest) pageContext. getRequest (). getContextPath () +"/"+ imageLink + ");

The JBPM flowchart is displayed successfully.

  1. JBPM 4.0 Configuration Analysis
  2. JBPM4 Architecture
  3. About MySQL configuration under jBPM
  4. A Brief Introduction to the complete jBPM and SSH instances
  5. An example of JBPM workflow engine testing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.