Please disable your adblock and script blockers to view this page

Search this blog

Wednesday, 13 September 2017

ADF Basics: Filter ViewObject data using getFilteredRows and RowQualifier


Sometimes we need to get filtered data from ViewObject using one or multiple conditions,
Though this is the very basic of framework yet new developers find it confusing.

There are two ways of filtering ViewObject

 1. In this we apply WHERE clause on ViewObject and it affects resultSet data, Suppose we have Department ViewObject and we want to see data of DepartmentId 4 on page after filtering, for this viewCritera, bind variables comes in action
ADF Basics: Apply and Change WHERE Clause of ViewObject at runtime programmatically

2. In this user want to get filtered data (Rows) in code only without any effect on ViewObject resultSet (page data), Here I am discussing this point

We can get filtered data from view object using two methods-



Using getFilteredRows method



To filter viewObject data using one condition (equals to attribute), We can use getFilteredRows method like this

//Get ViewObject Instance
        ViewObject deptVo = this.getDepartments1();
        //Filter data using getFilteredRows method
        Row filteredRows[] = deptVo.getFilteredRows("ManagerId", 103);
      
        //Get Values from returned rowset
        for (Row r : filteredRows) {
            System.out.println("Filtered Row- " + r.getAttribute("DepartmentName") + "\n");
        }

and output is


Using RowQualifier


RowQualifier is used to filter view object using multiple conditions, We can pass SQL WHERE clause in RowQualifier object.
It filters ViewObject data using that WHERE condition and returns an array of Row

        //Get ViewObject Instance
        ViewObjectImpl deptVo = this.getDepartments1();
        //Filter data using RowQualifier
        RowQualifier rq=new RowQualifier(deptVo);
        //Write condition in SQL query format
        rq.setWhereClause("DepartmentId=150 and ManagerId=103");
        Row filteredRows[] = deptVo.getFilteredRows(rq);
       
        //Get Values from returned rowset
        for (Row r : filteredRows) {
            System.out.println("Filtered Row- " + r.getAttribute("DepartmentName") + "\n");
        }

and output is

Cheers :) Happy Learning

1 comment :

  1. Hi Ashish, I need to show only Month and Year in af:Calender and also future months and Years are not allowed. please share me idea for how to develop this

    ReplyDelete