Follow by Email

Wednesday, 3 August 2016

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


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


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

3 comments :

  1. Thanks! I spend hours on the net searching for this good thing i found your link though a procustomwriting website that i was subscribing. Thank you for the very informative post.

    ReplyDelete
  2. Thank you for sharing this useful story.
    I think your shared information is helpful to me and who are want update their knowledge, who want to started their career with Oracle ADF Online Training.

    ReplyDelete