Bind two activities to one button in a Humantask fig6

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.

Bind two activities to one button in a Humantask Save

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

Bind two activities to one button in a Humantask fig1

 

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.

Bind two activities to one button in a Humantask fig2

 

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

Bind two activities to one button in a Humantask fig3

 

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

Bind two activities to one button in a Humantask fig4

 

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.

Bind two activities to one button in a Humantask fig5

 

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

Bind two activities to one button in a Humantask fig6

 

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;

public class MedewerkerHT {
    public MedewerkerHT() {
    }

    public void 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();
        }
    } 

    public void 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="#{customization.saveApprove}"
             text="#{wf:getResourceValue('APPROVE', 'bindings.customActions')}"
              disabled="#{!bindings.APPROVE.enabled}"
              action="closeTaskFlow"
              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.

One Response

  1. Arda Eralp July 4, 2014