Skip to main content

Manually refresh a row in a table after data manipulation

It's very common that the requirement asks to handle data manipulation for a ADF table. The data manipulation could be update, create or delete the table row and change some of the attributes in a table row. User interface experience should be achieve as that once the action button/link for the data manipulation has been pressed, the changed data should be reflected right away. It's not acceptable that the user has to refresh the page or search table to render the updated data.

Solution to this concern is easier to be fulfilled via declarative handling in Jdeveloper 11g. Setup the "refresh", "refresh condition" of the iterator that the table binds should be considered first to utilize the "PPR" feature of the ADF. But sometimes the declarative handling does not behave as expected, and you need to achieve this manually as a workaround.

Here is how I achieve this. Assume we have a manged bean to handle the data manipulation codes. After we selected a row in the table and press the data manipulation button, the codes for the data manipulation is executed, and should be followed by the below steps:

1). Get the row key for the selected Row.
2). Refresh the table manually. If you have a search functionality to refresh the table, we can use executeQuery of the binding View Object in our codes to refresh the table.
3). Set the current row of the refreshed table with the row key in step 1.

Here is the sample codes for this:

=====How to get the row key for the selected row in a table======
_Table is the binding name in managed bean

  private Key getRowKey() {
    Object _selectedRowData = _Table.getSelectedRowData();
    JUCtrlHierNodeBinding _nodeBinding = (JUCtrlHierNodeBinding)_selectedRowData;
    Key _rowKey = _nodeBinding.getRowKey(); 
    return _rowKey;
  }

=====How to set the current row in the a table with a given row key=====

  private void setSelectedRow(Key rowKey) {  
    BindingContainer bc = BindingContext.getCurrent().getCurrentBindingsEntry();
    OperationBinding oper2 = bc.getOperationBinding("executeQuery");
    oper2.execute();
    CollectionModel _tableModle = (CollectionModel)_Table.getValue();
    JUCtrlHierBinding _tableBinding = (JUCtrlHierBinding)_tableModle.getWrappedData();
    DCIteratorBinding _tableIteratorBinding = _tableBinding.getDCIteratorBinding();
    _tableIteratorBinding.setCurrentRowWithKey(rowKey.toStringFormat(true));
  }

Comments

mate thanks so much, i was looking for such a script code, you made my day hehe... keep it coming pls i subscribed to your blog because i like it very much!