Saturday, August 18, 2012

Create Row as last row in table


Source: https://blogs.oracle.com/jdevotnharvest/entry/how_to_add_new_adf

public String onRowCreate() {
 BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();
 //access the name of the iterator the table is bound to. Its "allDepartmentsIterator"
 //in this sample
 DCIteratorBinding dciter = (DCIteratorBinding) bindings.get("allDepartmentsIterator");
 //access the underlying RowSetIterator
 RowSetIterator rsi = dciter.getRowSetIterator();
 //get handle to the last row
 Row lastRow = rsi.last();
 //obtain the index of the last row
 int lastRowIndex = rsi.getRangeIndexOf(lastRow);
 //create a new row
 Row newRow = rsi.createRow();
 //initialize the row
 newRow.setNewRowState(Row.STATUS_INITIALIZED);
 //add row to last index + 1 so it becomes last in the range set
 rsi.insertRowAtRangeIndex(lastRowIndex +1, newRow); 
 //make row the current row so it is displayed correctly
 rsi.setCurrentRow(newRow);                          
 return null;
}  
For the table to show the newly created row after this ensure:

1. The table is configured to always show the current selected row by setting 
 its displayRow property to selected
2. The table is PPR'ed after the row is created, which can be done declarative 
using the PartialTriggers property of the table pointing to the ID of the command creating the new row

No comments:

Post a Comment