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.
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.