Adding the command-bar component to a JSF application

Add the Business Process Choreographer Explorer list component to a JavaServer Faces (JSF) application to display a bar with buttons. These buttons operate on the details view of an object or the selected objects in a list.

Why and when to perform this task

Each action in the command bar is represented by a command button and a command that is run when the user clicks the button in the user interface. You can add and extend this component in your JSF application.

Steps for this task

  1. Add the command-bar component to the JavaServer Pages (JSP) file.

    Add the bpe:command tag to the <h:form> tag.

    The following example shows how to add a command-bar component to display some of the properties for a task instance.

    <h:form>
    
       <bpe:commandbar model="#{TaskInstanceList}">
          <bpe:command commandID="Refresh" >
                       action="#{TaskInstanceList.refreshList}"
                       label="Refresh"/>
    
          <bpe:command commandID="MyClaimCommand" >
                       label="Claim" >
                       commandClass="<customcode>"/> 
       </bpe:commandbar>
    
    </h:form>

    The model attribute refers to the TaskInstanceList managed bean. This bean provides the properties of the Java object and it must implement the ItemProvider interface. This interface is also implemented by the BPCListHandler and the BPCDetailsHandler class.

  2. Optional: Configure the managed bean that is referred to in the bpe:details tag.

    If the command operates on the preconfigured list handler or details handler, no other configuration is required. If you have changed the configuration for either of these handlers, you must update the information in the JSF configuration file.

  3. Add the custom code to implement the custom commands to the configuration file.

    The following code snippet shows how you might extend the command bar to add a custom command, for example, a claim command that is implemented with the MyClaimCommand class.

    public class MyClaimCommand implements Command {
    
      public String execute(List selectedObjects) throws ClientException {
    	    if( selectedObjects != null && selectedObjects.size() > 0 ) {
      	     try {
             // Determine HumanTaskManagerService from an HTMConnection bean. 
             // Configure the bean in the faces-config.xml for easy access 
             // in the JSF application.
    		       FacesContext ctx = FacesContext.getCurrentInstance();
             ValueBinding vb = 
               ctx.getApplication().createValueBinding("{htmConnection}");
             HTMConnection htmConnection = (HTMConnection) htmVB.getValue(ctx);
             HumanTaskManagerService htm = 
                htmConnection.getHumanTaskManagerService();
    
             Iterator iter = selectedObjects.iterator() ;			
             while( iter.hasNext() ) {
               try {
                    TaskInstanceBean task = (TaskInstanceBean) iter.next() ;
                    TKIID tiid = task.getID() ; 
    						
                    htm.claim( tiid ) ;
                    task.setState( new Integer(TaskInstanceBean.STATE_CLAIMED ) ) ;
    						
               }
               catch( Exception e ) {
                 ;			// Error while iterating or claiming task instance.
                      // Ignore for better understanding of the sample.
               }
             }
           }
           catch( Exception e ) {
             ; 	// Configuration or communication error.
               // Ignore for better understanding of the sample
           }
         }
         return null;
      }
    
     // Default implementations
     public boolean isMultiSelectEnabled() { return false; }
     public boolean[] isApplicable(List itemsOnList) {return null; }
     public void setContext(Object targetModel) {; // Not used here }
    }

    The command checks the preconditions and any other prerequisites, for example, the correct number of selected items. It then retrieves a reference to the human task API, HumanTaskManagerService. The command iterates over the selected objects and tries to process them.

    The task is claimed through the HumanTaskManagerService API by an ID. If there is no exception, the state is updated for the corresponding TaskInstanceBean object. This action avoids retrieving the value of the object from the server again.

Your JSF application contains the details component functionality.

Terms of use | | Broken links

Last updated: Tue Feb 21 17:21:51 2006

(c) Copyright IBM Corporation 2005.
This information center is powered by Eclipse technology (http://www.eclipse.org)