X

The blog for hints & tips about Oracle Application Development Framework and Mobile Application Framework

Problem with deleting table rows using ctrl+a for row selection

Frank Nimphius
Master Principal Product Manager

The following code is commonly shown and
documented for how to access the row key of selected table rows in an ADF Faces
table configured for multi row selection.

public void onRemoveSelectedTableRows(ActionEvent actionEvent) {
   RichTable richTable = … get access to your table instance …
   CollectionModel cm =(CollectionModel)richTable.getValue();
   RowKeySet rowKeySet = (RowKeySet)richTable.getSelectedRowKeys();       
 
   for (Object key : rowKeySet) {
      richTable.setRowKey(key);
      JUCtrlHierNodeBinding rowData = (JUCtrlHierNodeBinding)cm.getRowData();
      // do something with rowData e.g.update, print, copy
  }
   //optional, if you changed data, refresh the table      
  
AdfFacesContext adfFacesContext = AdfFacesContext.getCurrentInstance();
adfFacesContext.addPartialTarget(richTable);  
return null;
}

The code shown above works for 99.5 % of all
use cases that deal with multi row selection enabled ADF Faces tables, except
for when users use the ctrl+a key to mark all rows for delete. Just to make
sure I am clear: if you use ctrl+a to mark rows to perform any other operation
on them – like bulk updating all rows for a specific attribute – then this
works with the code shown above. Even for bulk row delete, any other mean of
row selection (shift+click and multiple ctrl+click) works like a charm and the
rows are deleted.

So apparently it is the use of ctrl+a that
causes the problem when deleting multiple rows of an ADF Faces table. To
implement code that works for all table selection use cases, including the one
to delete all table rows in one go, you use the code shown below.

public void onRemoveSelectedTableRows(ActionEvent actionEvent) {
  RichTable richTable = … get access to your table instance …
  CollectionModel cm = (CollectionModel)richTable.getValue();
  RowKeySet rowKeySet = (RowKeySet)richTable.getSelectedRowKeys();
  Object[] rowKeySetArray = rowKeySet.toArray();   

  for (Object key : rowKeySetArray){          
    richTable.setRowKey(key);
    JUCtrlHierNodeBinding rowData = (JUCtrlHierNodeBinding)cm.getRowData();                              rowData.getRow().remove();
  }

 
AdfFacesContext adfFacesContext = AdfFacesContext.getCurrentInstance();         
adfFacesContext.addPartialTarget(richTable);
}

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.