ADF Basics: Iterate over master detail viewObject using view link accessor

Sharing is Caring

Hello All

This post is about iterating over master and it’s child view object using view link accessor, this is very basic thing of framework still some find (those who are starting with ADF) it difficult so I thought to write it here

Here I am using Departments and Employees table of HR Schema to create Master-Detail relation and due to view link relation, Department viewObject has view link accessor of Employees viewObject


This view link accessor contains rows for corresponding row of master (Departments) viewObject, It returns different rowset (list of Employees) for each record of Departments viewObject and we can programmatically access this view link accessor for each master record

view link accessor

 

Code in AMImpl to Iterate over Master and Detail view object records

import oracle.jbo.Row;
import oracle.jbo.RowSet;
import oracle.jbo.RowSetIterator;
import oracle.jbo.ViewObject;

/**
* This is the method to iterate over Departments and corresponding Employees records
*/
public void iterateMasterDetail() {
//Get Master ViewObject
ViewObject deptVo = this.getDepartmentsView();
//Create iterator to iterate over master viewObject
RowSetIterator rsi = deptVo.createRowSetIterator(null);

while (rsi.hasNext()) {
//Get Master ViewObject Row
Row departmentsRow = rsi.next();
System.out.println(“Department Name :” + departmentsRow.getAttribute(“DepartmentName”));
//Get Corresponding child viewobject accessor
RowSet rs = (RowSet) departmentsRow.getAttribute(“EmployeesView”);

//Iterate over child viewObject rows for corresponding master record
while (rs.hasNext()) {
Row r = rs.next();
System.out.println(” Employee : “ + r.getAttribute(“FirstName”) + ” “ +
r.getAttribute(“LastName”));
}
}
//Close Master viewObject iterator
rsi.closeRowSetIterator();
}

Add this method to client interface of Application Module and Run Application Module to check it

Output on log

Cheers 🙂 Happy Learning

Related Posts

An Oracle ACE, Blogger, Reviewer, Technical Lead working on Oracle ADF

0 thoughts on “ADF Basics: Iterate over master detail viewObject using view link accessor”

Leave a Reply

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