Bind two activities to one button in a Humantask

Ever forgot to Save your changes in Humantasks before pressing the Approve or Reject button?

In a SOA environment I have a humantask in a BPEL process. The humantask has an Approve and a Reject outcome.
The humantask offers the possibility to change al kinds of process related data. By default these changes are not saved when you press the Approve or Reject button. As a result It happens often that changes are not saved by making the mistake not saving changes before Approvement.

image1

Change the default button behaviour

In this blog I will decribe how to change the behaviour behind the ‘Approve’ button. I will change it to ‘Save and Approve’. On first hand I though this would be very simple. Add a second action to the button and tha’s all. But it is not possible to directly bind multiple actions to a button. However it is still possible by binding a new action to the button that on it’s turn executes multiple actions.

This can be implemented with a Managed Bean. I will descibe how to create the Managed Bean and to bind it to the Approve  and Reject button. 

At first, open the humantask (jspx file). In source mode find the ‘Approve’ commandToolbarButton.

image2

Change the values of the Action and ActionListener properties. You can do this directly in the source code or via the properties window in the bottom-right. I prefer this last option because it makes things a litle easier.

Select the left arrow behind Action. Then select ‘closeTaskFlow’.  This takes care of closing the taskform after pressing the Approve button.

image3

Now, select the right arrow behind ActionListener. Then select Edit. The following window appears.

image4

Select ‘New’ behind Managed Bean.
Specify the Bean details as shown in the image below:

image5

After pressing OK we will get back in the ’Edit Property’ window. The name of the new Managed Bean is shown.
Add a method to the Bean. Press New behind Method.

image6

Specify a Method name (e.g. saveApprove) and press OK

image7

Press OK again.

A java class ‘MedewerkerHT.java’ is now available in the Application Source. Change/replace the source code of this class:

package amis.nl;import javax.faces.event.ActionEvent;import oracle.adf.model.BindingContext;import oracle.binding.BindingContainer;import oracle.binding.OperationBinding;publicclassMedewerkerHT{
    publicMedewerkerHT(){
    }

    publicvoid saveApprove(ActionEvent actionEvent){

        // Save changes
  BindingContainer bindings =BindingContext.getCurrent().getCurrentBindingsEntry(); 
        OperationBinding method = bindings.getOperationBinding("update"); 
        if(method !=null){
            method.execute(); 
        }

       // Perform original function
        bindings =BindingContext.getCurrent().getCurrentBindingsEntry(); 
        method = bindings.getOperationBinding("APPROVE"); 
        if(method !=null){
            method.execute();
        }
    } 

    publicvoid saveReject(ActionEvent actionEvent){
        // Save changes
  BindingContainer bindings =BindingContext.getCurrent().getCurrentBindingsEntry(); 
        OperationBinding method = bindings.getOperationBinding("update"); 
        if(method !=null){
            method.execute(); 
        }

        // Perform original function
        bindings =BindingContext.getCurrent().getCurrentBindingsEntry(); 
        method = bindings.getOperationBinding("REJECT"); 
        if(method !=null){
            method.execute();
        }
    } 
}

The class contains the implementation for both the Approve and the Reject Button.

In the humantask the sourcecode of the commandToolbarButton is changed into:

<af:commandToolbarButton actionListener="#{<strong>customization.saveApprove</strong>}"
             text="#{wf:getResourceValue('APPROVE', 'bindings.customActions')}"
              disabled="#{!bindings.APPROVE.enabled}"
              action="<strong>closeTaskFlow</strong>"
              partialSubmit="false"
              visible="#{wf:isCustomActionAvailable('APPROVE', 'bindings.customActions')}"
              id="ctb2">
              <f:attribute name="DC_OPERATION_BINDING" value="bindings.APPROVE">
</af:commandToolbarButton>

The actionListener is binded to the new created Managed Bean

For the reject button almost the same steps are required. Even though it is not needed to create the Bean and Method again. Now it is possible to select the existing one.

The two functions are now binded to the same button.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s