Creating a CommandHandler that provides a queryGroupWorkItems command

The third step of creating a group worklist is to add a custom CommandHandler that implements a new queryGroupWorkItems command.

The source files for setting up a group worklist are stored in the <MQWFDir>/smp/WebClient/groupwl directory. To create a CommandHandler:

  1. Change to the step3 directory.
  2. Copy the GroupWorkListHandler.start file to GroupWorkListHandler.java.
  3. Edit the GroupWorkListHandler.java file, and add GenericCommandHandler as base class. This is a helper class that implements the CommandHandler interface and maps servlet commands in HTTP requests to methods that have the same name as the command. Alternatively, you can implement your own dispatching logic by overriding the execute() method.
  4. Create an instance of the GroupWorkListViewer class in the init() method and pass a pointer to this as constructor parameter. This constructor will be added to the viewer in a later step.
  5. In the onLogon method, add a condition so that the groupListOwner is not assigned to the GroupWorkListViewer, but uses the default viewer configured in the WebClient.properties file instead.
  6. In the queryGroupWorkItems method, add the line to query the worklist OID from the HTTP request. The name of this parameter is id.

    Because the GroupWorkListHandler class inherits from the GenericCommandHandler class, this queryGroupWorkItems method is called automatically whenever the servlet of the Web client gets a queryGroupWorkItems command. This is a wrapper method only, and the actual implementation is in an overloaded method. As a result, the command can be invoked internally from the GroupWorkListViewer class, or externally through an HTTP request.

  7. For the implementation of queryGroupWorkItems, query the work items on the list with the OID workListOID. Then, add the condition that defines when new work items are to be transferred to the worklist of the user. Finally, add the call to perform the work item transfer.
  8. Note:
    To perform the work item transfer, you can add either of the following method calls to return the response page:

    return viewer.queryGroupWorkItemsResponse(context);
    With this call, you directly call the viewer that you specify for 'viewer'. You can also use the method call as it is used in the template file:
    return builtin.render("queryGroupWorkItems", context);
    With this call, you use the viewer that you have configured for the Web client.
  9. Copy the GroupWorkListViewer.start file to GroupWorkListViewer.java.
  10. Edit the GroupWorkListViewer.java file, then check the new constructor and the enhanced init() method. Note that the constructor takes a GroupWorkListHandler object as parameter. Therefore, you can no longer use the GroupWorkListViewer class in the DefaultViewer setting. The DefaultViewer setting requires the specified class to have a default (that is, no-argument) constructor.
  11. In the logonResponse method, add the call to create the group list if it does not yet exist. Use OWNER='groupListOwner' as filter, and groupListThreshold as query threshold.
  12. At the end of the logonResponse method, call the GroupWorkListHandler with the appropriate parameters to create the initial worklist for the currently logged-on user. This results in a call to the queryGroupWorkItemsResponse method of the viewer. Add the signature for this method.
  13. When you created the JSP file to display the worklist in step 2 (GroupWorkList.jsp), a 'Refresh' button, a 'Logoff' button, work item methods, such as transferItem and cancelWorkItem were offered. Because the GroupWorkListViewer inherits from the JSPViewer class, the response pages that are created for these commands are also inherited. Therefore, it is necessary to override the appropriate xxxResponse methods to ensure that the correct worklist is created and displayed by the JSPViewer

  14. Add the implementation of the transferItemResponse method.
  15. Copy the GroupWorkList.start file to GroupWorkList.jsp.
  16. Edit the GroupWorkList.jsp file, then add the code to create the new 'Refresh' command used by the button. Instead of invoking the built-in queryWorkItems command, now invoke the new queryGroupWorkItems command. Use "x-queryGroupWorkItems" as the command string so that you can avoid name clashes with any future built-in commands.
  17. Built-in commands are always called first. If you have added a queryGroupWorkItems command to the BuiltinHandler of the servlet, the command of the GroupWorkListHandler command is no longer called. To avoid this problem, add the "x-" prefix to custom commands.

  18. Use the ApplicationContext.getCommand() method to pass the groupListOID parameter to GroupWorkListHandler.queryGroupWorkItems.
  19. To deploy the JSP, copy the GroupWorkList.jsp file to the <MQWFDir>/cfgs/<cfgID>/WebClient/webpages/forms directory.
  20. To compile your files, change to the parent directory and run:
    jc step3\*.java
  21. Edit the WebClient.properties file and change the line reading
    DefaultViewer=com.ibm.workflow.servlet.sample.GroupWorkListViewer
    to
    #DefaultViewer=com.ibm.workflow.servlet.client.JSPViewer
    Then, change the line reading
    #CommandHandler=com.ibm.workflow.servlet.sample.CommandHandlerAdapter
    to
    CommandHandler=com.ibm.workflow.servlet.sample.GroupWorkListHandler
    to activate the custom command handler class.
  22. Restart your Web server and log on to MQ Workflow using the http://localhost/MQWFClient-<cfgID>/RTC.html page.
  23. Compare your solution with the provided solution (files names: GroupWorkListHandler.sol, GroupWorkListViewer.sol, and GroupWorkList.sol).
Go back