Search This Blog

Friday, August 17, 2012

Fetch all the rows selected from a UI Table in ADF

Following is an example to get all the rows selected from a UI table in ADF.

How do we enable multiple selections on a table ?

When you drag and drop a VO on to a page, user is presented with different options to represent the data from the VO. Choose the option of ADF table and select the option of "multiple rows" under "Row Selection" (Other options available are None, Single row)

If there is no backing bean or Managed bean enabled while creating the page then create binding for the table, how ?
-------------------------------------------------------------------------
Click on the table in the structure panel, Go to property inspector - > Advance -> Binding - > Choose Edit -> Create new managed bean & create new porperty as "table1".

Above action creates a getter  and setter method for the "table1" as below in the bean.

    private RichTable table1;
   
    public void setTable1(RichTable table) {
        this.table = table;
    }

    public RichTable getTable1() {
        return table;
    }

-------------------------------------------------------------------------



Now on button action or row selection listener use the following code to get an handle to the selected row.

RichTable table = this.getTable1();

CollectionModel model = (CollectionModel) table.getValue();
JUCtrlHierBinding treeBinding = (JUCtrlHierBinding) model.getWrappedData();

RowKeySet rowKeys = table.getSelectedRowKeys();
Iterator iterator = rowKeys.iterator();

while (iterator.hasNext()) {
         List key = (List) iterator.next();                  
         JUCtrlHierNodeBinding nodeBinding = treeBinding.findNodeByKeyPath(key);
         Row rw = nodeBinding.getRow();
}

1 comment: