Traverse POJO based ADF treeTable, Get Child nodes of selected parent

Sharing is Caring

Previously I have posted about populating ADF treeTable programmatically and getting selected records from POJO based treeTable

This post is next in that series and here I am extending the same sample application that shows a tree of Seasons and it’s characters
First, we will see How to traverse a POJO based ADF treeTable (Iterate through all nodes of treeTable)

Basic idea is to get treeTable Collection Model and iterate over it to get all nodes value, To get CollectionModel created a treeTable component binding in the managed bean

//Component Binding of af:treeTable in bean 
private RichTreeTable treeTableBind;

public void setTreeTableBind(RichTreeTable treeTableBind) {
this.treeTableBind = treeTableBind;

public RichTreeTable getTreeTableBind() {
return treeTableBind;

and POJO based treeTable looks like this

Dropped a button page to traverse treeTable, Created ActionListener in Managed Bean

Code to Traverse POJO based treeTable:

    /**Method to iterate through all nodes of treeTable (parent and child both)
     * @param actionEvent
    public void traverseTreeTableAction(ActionEvent actionEvent) {
        //Get TreeTable CollectionModel
        CollectionModel treeModel = null;
        treeModel = (CollectionModel) this.getTreeTableBind().getValue();
        //Creata an Object to RowKeys and collection model to it
        RowKeySet rks = new RowKeySetTreeImpl();
        //Iterate Over RowKeySet to get all nodes
        for (Object o : rks) {
            //Here treeTable shows list of Seasons objects
            Seasons season = (Seasons) treeModel.getRowData();
            System.out.println("  " + season.getName());

On button click, see the output on the console

The output on Console

Next is to traverse a selected parent node to get it’s all child nodes

Code to get all child of selected node:

    /**Method to iterate through all childs of selected node of treeTable
     * @param actionEvent
    public void traverseSelectedNodeTreeTableAction(ActionEvent actionEvent) {
        //Get Collection Model from treeTable binding
        CollectionModel treeModel = null;
        treeModel = (CollectionModel) this.getTreeTableBind().getValue();
        RowKeySet selectedChildKeys = getTreeTableBind().getSelectedRowKeys();
        if (!selectedChildKeys.isEmpty()) {
            List<Seasons> seasonList = (List<Seasons>) treeModel.getWrappedData();
            //Create iterator from RowKeySet
            Iterator selectedCharIter = selectedChildKeys.iterator();
            //Iterate over RowKeySet to get all selected childs of treeTable
            while (selectedCharIter.hasNext()) {
                List val = (List);
                //Check that selected node should be parent node
                if (val.size() == 1) {
                    //Get Seasons (Parent) List of selected row
                    Seasons s = seasonList.get(Integer.parseInt(val.get(0).toString()));
                    //Get character(Child) list of Seasons
                    List<Seasons> characters = s.getCharacters();
                    //Iterate over character list
                    Iterator iter = characters.iterator();
                    while (iter.hasNext()) {
                        Seasons sp = (Seasons);
                        System.out.println(" "+sp.getName());

On button click, see the output on the console

ADF treeTable
Output on Console

Sample ADF Application- Download
Cheers 🙂 Happy Learning

Related Posts

0 thoughts on “Traverse POJO based ADF treeTable, Get Child nodes of selected parent”

Leave a Reply

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