Get Selected records (Child/Parent) from POJO based ADF treeTable

Sharing is Caring

Hello All
Previously I have posted about How to create POJO based ADF treeTable and this the next post in series

In this post, I am talking about a very common requirement while using POJO based ADF treeTable
How can we get selected records (child/parent) from POJO based ADF treeTable?

For this post I am extending same sample application, Till now we have seen that how can we create POJO based treeTable
Now we’ll see that how to get it’s selected records

Next is creating af: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;

Added a button on the page and created it’s ActionListener in the managed bean,
See code is written in ActionListener to get selected records of af:treeTable

import org.apache.myfaces.trinidad.model.ChildPropertyTreeModel;
import org.apache.myfaces.trinidad.model.CollectionModel;
import org.apache.myfaces.trinidad.model.RowKeySet;
import org.apache.myfaces.trinidad.model.TreeModel;

import javax.faces.event.ActionEvent;

/**Method to get Selected row value from POJO based treeTable
 * To Know about creation of POJO based tree
 * Check-
 * @param actionEvent
public void getSelectedRowAction(ActionEvent actionEvent) {
//Get Collection Model from treeTable binding
CollectionModel treeModel = null;
treeModel = (CollectionModel) this.getTreeTableBind().getValue();
//Get selected row keys from treeTable
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);
//Get Seasons (Parent) List of selected row
Seasons s = seasonList.get(Integer.parseInt(val.get(0).toString()));
//Get charaters list of selected seasons
List<Seasons> characterList = s.getCharacters();
//If selected record is child (Character)
if (val.size() > 1) {
Seasons character = characterList.get(Integer.parseInt(val.get(1).toString()));
System.out.println("Charater Name-" + character.getName());
} else {
System.out.println("Season Name-" + s.getName());

Run and check application, selected some records (both parent and child)

POJO based ADF treeTable

On button click – selected records are printed on the console

Sample ADF Application – Download
Cheers 🙂 Happy Learning

Related Posts

Leave a Reply

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