Group Worklist - Tutorial Part 3

Part 3 describes how to add a custom CommandHandler that implements a new queryGroupWorkItems command, as outlined in the overview section of this tutorial.
  1. Change to the step3 directory.
  2. Copy GroupWorkListHandler.start to GroupWorkListHandler.java.
  3. Edit GroupWorkListHandler.java 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. In the init() method, create an instance of the GroupWorkListViewer class 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 WebClient.properties 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.
    Since GroupWorkListHandler inherits from the GenericCommandHandler class, this queryGroupWorkItems method will be called automatically whenever the Web Client's servlet 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) as well as externally (that is, through an HTTP request). What is the reason why the external method cannot be invoked internally also?
  7. For the implementation of queryGroupWorkItems, query the work items on the list with OID workListOID. Then, add the condition when new work items should be transferred to the user's worklist. Finally, add the call to perform the work item transfer.
  8. When returning the response page, what difference exists between directly calling
    return viewer.queryGroupWorkItemsResponse(context);
    and the approach used in the template file:
    return builtin.render("queryGroupWorkItems", context);
    ?
  9. Copy GroupWorkListViewer.start to GroupWorkListViewer.java.
  10. Edit GroupWorkListViewer.java and check the new constructor and the enhanced init() method. Note that the constructor takes a GroupWorkListHandler object as parameter. Therefore, the GroupWorkListViewer class can no longer be used in the DefaultViewer setting, which requires the class specified to have a default (that is, non-argument) constructor.
  11. In the logonResponse method, add the call to create the group list if it does not 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. Note that this will result in a call to the Viewer's queryGroupWorkItemsResponse method. Add the signature for this method.
  13. Remember the GroupWorkList.jsp JSP from step 2. In addition to the 'Refresh' and 'Logoff' buttons, work item methods, such as transferItem, cancelWorkItem were offered. Since GroupWorkListViewer inherits from the JSPViewer class, the response pages, which are created for these commands are also inherited. Therefore, it is necessary to override the appropriate xxxResponse methods to make sure that the restricted worklist is displayed instead of whatever page JSPViewer would create. Add the implementation of the transferItemResponse method.
  14. Copy GroupWorkList.start to GroupWorkList.jsp.
  15. Edit GroupWorkList.jsp and add 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. This helps to avoid name clashes with any future built-in commands, which are always called first. That is, if a queryGroupWorkItems command was added to the servlet's BuiltinHandler, the GroupWorkListHandler's command would no longer be called. Adding the "x-" prefix to custom commands helps to avoid the problem.
    Use the ApplicationContext.getCommand() method to pass the groupListOID parameter to GroupWorkListHandler.queryGroupWorkItems.
  16. To deploy the JSP, copy the file GroupWorkList.jsp to the <MQWFDir>/WebClient/webpages/forms directory.
  17. Change to the parent directory and run
    jc step3\*.java
    to compile your files.
  18. Edit the <MQWFDir>/WebClient/WebClient.properties file and change the line reading
    DefaultViewer=com.ibm.workflow.servlet.sample.GroupWorkListViewer
    back to
    #DefaultViewer=com.ibm.workflow.servlet.client.DefaultViewer
    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.
  19. Restart your Web server and logon to Workflow using the http://localhost/MQWFClient/RTC.html page.
  20. Finally, compare your solution to the one provided (files GroupWorkListHandler.sol, GroupWorkListViewer.sol, and GroupWorkList.sol).
Go back
© Copyright IBM Corporation 1999, 2001. All Rights Reserved.