Search on (Filtering) child nodes of af:treeTable using viewCriteria in Oracle ADF (11g,12c)

Sharing is Caring

Hello all
This post is about filtering child nodes of af:treeTable using view link accessor
In this tutorial, I have used Departments and Employees table of HR schema to create treeTable
see how to create treeTable-
http://www.awasthiashish.com/2012/11/tree-table-component-in-oracle.html
http://www.awasthiashish.com/2013/08/tree-table-component-with-declarative.html

treeTable look like this-

now next is to search on Employee Names

    • I have dropped an input text for the search string and a button to search on the page, here I am searching on the first name of employees

 

child nodes of af:treeTable

 

    • Now created a view Criteria in Employee viewObject to search on the first name

 

 

    • This viewCriteria doesn’t work directly on Employee viewObject, to search in treeTable we have to override createViewLinkAccessorRS method in Departments (master vo) VOImpl class, and in this method, we have to call Employees ViewCriteria explicitly , this will filter Employee Vo Rowset as per bind-variable value when a node is disclosed at runtime

/**
 * @param associationDefImpl
 * @param viewObjectImpl
 * @param row
 * @param object
 * @return
 */
protected ViewRowSetImpl createViewLinkAccessorRS(AssociationDefImpl associationDefImpl,
                                                      ViewObjectImpl viewObjectImpl, Row row, Object[] object) {

ViewRowSetImpl viewRowSetImpl = super.createViewLinkAccessorRS(associationDefImpl, viewObjectImpl, row, object);

String firstName = getFirstNm();
ViewCriteriaManager vcm = viewObjectImpl.getViewCriteriaManager();
ViewCriteria vc = vcm.getViewCriteria("EmployeesVOCriteria");
VariableValueManager vvm = vc.ensureVariableManager();
vvm.setVariableValue("BindFirstNm", firstName);
viewObjectImpl.applyViewCriteria(vc);
        return viewRowSetImpl;

        // return super.createViewLinkAccessorRS(associationDefImpl, viewObjectImpl, row, object);
    }

 

    • To pass bind-variable value I have created a variable and it’s accessors in VoImpl and exposed ‘setter’ method to the client interface that is further used by the managed bean

    private String firstNm;
    public void setFirstNm(String firstNm) {
        this.firstNm = firstNm;
    }

    public String getFirstNm() {
        return firstNm;
    }

 

    • Now this setter method is called in managed bean search button action to set bind variable value

    /**Method to search in treeTable childs
     * @param actionEvent
     */
    public void searchAction(ActionEvent actionEvent) {
        if (firstNmBind.getValue() != null) {
            OperationBinding ob = executeOperation("setFirstNm");
            // firstNmBind is binding of inputText
            ob.getParamsMap().put("firstNm", firstNmBind.getValue().toString());
            ob.execute();
            /* Method Expand treeTable after Search see- 
             http://www.awasthiashish.com/2013/10/expand-and-collapse-aftreetable.html*/
            expandTreeTable();
            AdfFacesContext.getCurrentInstance().addPartialTarget(treeTabBind);

        }
    }

 

  • Run your application and see-

    Sample ADF Application- Download

    Cheers 🙂 Happy Learning

Related Posts

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

0 thoughts on “Search on (Filtering) child nodes of af:treeTable using viewCriteria in Oracle ADF (11g,12c)”

  1. Hi Ashish, I tried implementing this in Master – Detail Tables. and the said method never get invoked. my VOs are readonly based on SQL Query. Can you please help with pointers

Leave a Reply

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