Monday, May 12, 2014

Select and Unselect All Rows in ADF Table via backing bean

Select :

1) Create a table binding in the backing bean

     CollectionModel model = (CollectionModel)getMessagesTable().getValue();

     getMessagesTable() is the binding method to the adf table.

Actual Code :

 public void selectAllRecords(ActionEvent actionEvent) {
        RowKeySet rks = new RowKeySetImpl();
        CollectionModel cm= (CollectionModel)getMessagesTable().getValue();
        int count= cm.getRowCount();
        for (int i = 0; i < count; i++) {
            Object key = cm.getRowKey();

Unselect :

The above method will make all the records selected in the UI. we will see how to unselect all the rows.

public void clearAllRecords(ActionEvent actionEvent) {

   //This commented part is just to make sure the selected records are still the same before we clear 

     DCBindingContainer bindings =   (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
        DCIteratorBinding msgIter = bindings.findIteratorBinding("Messages1Iterator");
       RowSetIterator msgRSIter = msgIter .getRowSetIterator();
        RowKeySet rks = getMessagesTable().getSelectedRowKeys();

       Iterator it = rks.iterator();
            Key key = (Key)((List);
            System.out.println("Row key:"+key);
            Row currentRow = msgRSIter .getRow(key);