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:
- <!-- 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>
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.
- 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;
- }
- });
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() {
- public Object doInJbpm(JbpmContext context) {
- processDefinition = context.getGraphSession().loadProcessDefinition(processDefinitionId);
- bytes = processDefinition.getFileDefinition().getBytes("processimage.jpg");
- return null;
- }
- });
-
- OutputStream out = response.getOutputStream();
- out.write(bytes);
- out.flush();
- }
- }
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.
- JBPM 4.0 Configuration Analysis
- JBPM4 Architecture
- About MySQL configuration under jBPM
- A Brief Introduction to the complete jBPM and SSH instances
- An example of JBPM workflow engine testing