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++) {
            cm.setRowIndex(i);
            Object key = cm.getRowKey();
             rks.add(key);
       }
     
       
        getCtoMessagesTable().setSelectedRowKeys(rks);
       
   }

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) {
  
       getMessagesTable().getSelectedRowKeys().clear();

  
   /*       
   //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();
   
        while(it.hasNext()){
           
           
            Key key = (Key)((List)it.next()).get(0);
            System.out.println("Row key:"+key);
            Row currentRow = msgRSIter .getRow(key);
            System.out.println("Config:"+currentRow.getAttribute("Name"));
              
           
            }
           
        */

    
                                                               
       
    }

No comments:

Post a Comment