Version 4

    Ok.  I asked for this too, but eventually I had to figure it out for myself.  It really isn't that hard.  Let me first say that there were a few documentation changes for the 3.0.1 release that made the light bulb go off for me.  So look at the readme files again.  Also look at the tests in jbpm\src\java.jbpm.test.  Those were extremely helpful.  There were a few cases were the User Guide was wrong and I found the correct solution by looking at their tests.

     

    Here's an example of an action using jBPM.  I use Spring (that's my shameless plug) to encapsulate my business logic, but it should get the concept across.  All this action does is retrieve a users task list.

     

    public ActionForward search(ActionMapping mapping, ActionForm form,
                HttpServletRequest request, HttpServletResponse response)
                throws Exception
    {
       if (log.isDebugEnabled())
          log.debug("Entering 'search' method");
            
       // These are my "Spring" beans that contain the business logic.
       // The BpmManager is where I have my jBPM logic
       UserManager userMgr = (UserManager) getBean("userManager");
       BpmManager bpmMgr = (BpmManager) getBean("bpmManager");
       com.pragmatic.model.User user = null;
       // Looking up the user.  Not important how this works, just need to know
       // that I'm getting a user
       user = userMgr.getUser(getUser(request.getSession()).getId());
    
       List tasks = bpmMgr.getTaskList(user.getUsername());
            
       log.debug("User's # of tasks = " + tasks.size());
            
       // Store the tasks in the request
       request.setAttribute(Constants.TASK_LIST,tasks);
    
       return mapping.findForward("list");
    }
    
    

     

     

    Here's my implementation of the getTaskList method from BpmManager.

     

    public List getTaskList(String actorid)
        {
            JbpmSession jbpmSession = sessionFactory.openJbpmSession();
            jbpmSession.beginTransaction();
    
            TaskMgmtSession taskSession =    jbpmSession.getTaskMgmtSession();
            List tasks = taskSession.findTaskInstances(actorid);
    
            jbpmSession.commitTransaction();
            jbpmSession.close();
    
            return tasks;
        }
    

     

    In my jsp I just use displaytag to show the task list in a tabular form.  The variable taskList points to the List I set in the request in my action.  Each item in the list is a TaskInstance so I can get their properties by name, e.g. id.

     

    <display:table
         name="${taskList}" cellspacing="0" cellpadding="0" requestURI=""
         defaultsort="1" export="false" id="users" pagesize="25"
         styleClass="list userList">
         <display:column property="id" sort="true" headerClass="sortable"
              width="17%" paramId="id" paramProperty="id" titleKey="taskForm.id" ></display:column>
         <display:column property="name" sort="true" headerClass="sortable"
              width="20%" titleKey="taskForm.name" ></display:column>
         <display:column property="create" sort="true" headerClass="sortable"
              decorator="com.receller.webapp.decorator.ShortDateDecorator"
              titleKey="taskForm.create" ></display:column>
         <display:setProperty name="paging.banner.item_name" value="task" ></display:setProperty>
         <display:setProperty name="paging.banner.items_name" value="tasks" ></display:setProperty>
    </display:table>
    

     

    Hope this helps.  Now back to work.