Implementing Commit and Rollback programmatically in ADF Task Flow

Tweet about this on TwitterShare on Facebook1Share on LinkedIn5Share on Google+0

Sometimes the Task Flow Return component from ADF Task Flow, doesn’t meet our use case requirements and we have to commit or rollback a transaction programmatically. Two cases that you will probably use this approach are:

  • Commit or rollback a transaction and stay in the same Task Flow.
  • Add some complex code for these operations (Commit and Rollback).

In this post we will commit a transaction programmatically without quit the current page. We will also rollback a transaction programmatically.
Download the sample application: CommitRollbackProgrammaticApp.zip

Create an application according to image below.

implementing-commit-and-rollback-programmatically-in-adf-task-flow1

Configure the Task Flow.

implementing-commit-and-rollback-programmatically-in-adf-task-flow2

implementing-commit-and-rollback-programmatically-in-adf-task-flow3

Double-click on ViewDepartment and create the page.
Drag the DepartmentView1 from Data Controls pane and drop inside ViewDepartment page. Select Table | ADF Read-only Table.
Select Single Row and click on OK.
Include a button after the af:table tag, and configure it.

implementing-commit-and-rollback-programmatically-in-adf-task-flow4

Go to DepartmentTaskFlow, double-click on EditDepartment and create the page.
Drag the DepartmentView1 from Data Controls pane and drop inside EditDepartment page.
Select Form | ADF Read-only Form, and click on OK.
Include two buttons after the af:panelFormLayout tag, and configure them.

implementing-commit-and-rollback-programmatically-in-adf-task-flow5

Go to DepartmentTaskFlow, double-click on Commit component and create the DepartmentBean.
Create the commit method too.

implementing-commit-and-rollback-programmatically-in-adf-task-flow6

implementing-commit-and-rollback-programmatically-in-adf-task-flow7

Go to DepartmentTaskFlow, double-click on Rollback component and select the DepartmentBean.
Create the rollback method.

implementing-commit-and-rollback-programmatically-in-adf-task-flow8

Go to DepartmentBean and implement the methods with these code snippets.

public void commit() {
   BindingContext bc = BindingContext.getCurrent();
   String dcfName = bc.getCurrentDataControlFrame();
   DataControlFrame dcf = bc.findDataControlFrame(dcfName);
   dcf.commit();
}

public void rollback() {
   BindingContext bc = BindingContext.getCurrent();
   String dcfName = bc.getCurrentDataControlFrame();
   DataControlFrame dcf = bc.findDataControlFrame(dcfName);
   if (dcf.isTransactionDirty()) {
      dcf.rollback();
   }
}

implementing-commit-and-rollback-programmatically-in-adf-task-flow9

Now we have to define the Fixed Outcome attribute from Commit and Rollback components.
Go to DepartmentTaskFlow, select Commit component and change the Fixed Outcome attribute value to commit. After that, select Rollback component and change the Fixed Outcome attribute value to goViewDepartment.

implementing-commit-and-rollback-programmatically-in-adf-task-flow10

implementing-commit-and-rollback-programmatically-in-adf-task-flow11

Save all and run the Task Flow.
To test commit operation, select a department and click on Edit.

implementing-commit-and-rollback-programmatically-in-adf-task-flow12

Make some changes and click on Save.

implementing-commit-and-rollback-programmatically-in-adf-task-flow13

Click on Back to go to list of departments.
Observe the department that you have edited.

implementing-commit-and-rollback-programmatically-in-adf-task-flow14

To test rollback operation, select a department and make some changes.

implementing-commit-and-rollback-programmatically-in-adf-task-flow15

implementing-commit-and-rollback-programmatically-in-adf-task-flow16

If you just click on Back, the changes are rolled back.

implementing-commit-and-rollback-programmatically-in-adf-task-flow17

Tweet about this on TwitterShare on Facebook1Share on LinkedIn5Share on Google+0

Author: Waslley Souza

Consultor Oracle com foco em tecnologias Oracle Fusion Middleware e SOA. Certificado Oracle WebCenter Portal, Oracle ADF e Java.

Leave a Reply

Your email address will not be published. Required fields are marked *