Get selected row (single/multiple) from POJO based table in ADF

Sharing is Caring

Previously I have posted about populating af:table from the managed bean using POJO and adding records in it, Check this-
Populate af:table programmatically from managead bean using POJO 
In this post, I am extending the previous post application
This post is about getting selected row from POJO based table, It is a common requirement while using af:table based on POJO

Get single row using custom selection listener-

SelectionListener handles selection event of the table, whenever the user selects a row in the table, selection listener is fired
Set table RowSelection property to single (to select one row at a time) or multiple (to select multiple rows) and create a custom selection listener in the managed bean that will handle table’s selection event


See selection listener code in managed bean we can get selected row using this –

import org.apache.myfaces.trinidad.event.SelectionEvent;

/**Method to get selected row(single)
 * @param selectionEvent
public void tableSelection(SelectionEvent selectionEvent) {
//Get table from selectionEvent
RichTable richTable = (RichTable) selectionEvent.getSource();
//Cast to the List that populates table
PersonBean row = (PersonBean) richTable.getSelectedRowData();
//Get the attributes (column) from list

Now check this –

The output on console 🙂


Get single/multiple selected rows on a button click (ActionEvent)-

Set table RowSelection to multiple and select multiple rows using Ctrl key of your keyboard
and check this code to get multiple selected rows using RowKeySet, We can get all row using getSelectedRowKeys method


import org.apache.myfaces.trinidad.model.RowKeySet;
import java.util.Iterator;

/**Method to get all selected record in af:table
 * @param actionEvent
public void getSelectedRecord(ActionEvent actionEvent) {
//getTableBind is binding of table on page.
RowKeySet selectedEmps = getTableBind().getSelectedRowKeys();
//Create iterator from RowKeySet
Iterator selectedEmpIter = selectedEmps.iterator();

while (selectedEmpIter.hasNext()) {
String i =;
//personList is the list used to populate table and name is a column of table
//So here filter list using index and get values then
PersonBean rowIter = personList.get(Integer.parseInt(i));


Now run and check again –

The output on console 🙂

Sample ADF Application- Download
Cheers 🙂 Happy Learning

Related Posts

12 thoughts on “Get selected row (single/multiple) from POJO based table in ADF”

  1. Hi. I tried the code to get selected rowes in button click, but there are the following three errors.

    1) Method getTableBind() is not found
    2) Type PersonBean not found
    3) Type or Variable personList not found.

    What changes should I make or libraries should I include to fix this issue??

  2. I did this:
    public void seleccionarEvento(SelectionEvent selectionEvent) {
    List event = (List)Util.getValuePageFlowScope("eventos");
    RichListView lst = (RichListView)selectionEvent.getComponent();
    RowKeySet rowKey = lst.getSelectedRowKeys();
    int sel =(Integer)rowKey.toArray()[0];
    Eventos.Evento evento=(Eventos.Evento) event.get(sel);
    Util.setValuePageFlowScope("eventoSeleccionado", evento);

Leave a Reply

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