ADF 11G : How to Add a Row at the different place of the ADF Table?
Approach:1- Override the insertRow(row) method :
public class EmployeesViewImpl extends ViewObjectImpl {
/**
* This is the default constructor (do not remove).
*/
public EmployeesViewImpl() {
}
@Override
public void insertRow(Row row) {
super.insertRow(row);
row.removeAndRetain();
last();
next();
getDefaultRowSet().insertRow(row);
}
}
Approach:2- Calling the action:
public String insertRowAtFirstOfTable{
CollectionModel tableModel = (CollectionModel)getEmpTable().getValue();
JUCtrlHierBinding adfModel = (JUCtrlHierBinding)tableModel.getWrappedData();
DCIteratorBinding dciter = adfModel.getDCIteratorBinding();
NavigatableRowIterator nav=dciter.getNavigatableRowIterator();
Row newRow = nav.createRow();
newRow.setNewRowState(Row.STATUS_INITIALIZED);
nav.insertRowAtRangeIndex(0, newRow); dciter.setCurrentRowWithKey(newRow.getKey().toStringFormat(true));
return null;
}
public String insertRowAtLastOfTable() {
// Add event code here…
CollectionModel tableModel = (CollectionModel)getEmpTable().getValue();
JUCtrlHierBinding adfModel = (JUCtrlHierBinding)tableModel.getWrappedData();
DCIteratorBinding dciter = adfModel.getDCIteratorBinding();
NavigatableRowIterator nav=dciter.getNavigatableRowIterator();
Row newRow = nav.createRow();
newRow.setNewRowState(Row.STATUS_INITIALIZED);
Row lastRow = nav.last();
int lastRowIndex = nav.getRangeIndexOf(lastRow);
nav.insertRowAtRangeIndex(lastRowIndex+1, newRow);
dciter.setCurrentRowWithKey(newRow.getKey().toStringFormat(true));
return null;
}
public String addRowBeforeCurrentSelectedRow() {
// Add event code here…
CollectionModel tableModel = (CollectionModel)getEmpTable().getValue();
JUCtrlHierBinding adfModel = (JUCtrlHierBinding)tableModel.getWrappedData();
DCIteratorBinding dciter = adfModel.getDCIteratorBinding();
NavigatableRowIterator nav=dciter.getNavigatableRowIterator();
Row newRow = nav.createRow();
newRow.setNewRowState(Row.STATUS_INITIALIZED);
nav.insertRow(newRow); dciter.setCurrentRowWithKey(newRow.getKey().toStringFormat(true));
return null;
}
public String addRowAfterCurrentSelectedRow() {
// Add event code here…
CollectionModel tableModel = (CollectionModel)getEmpTable().getValue();
JUCtrlHierBinding adfModel = (JUCtrlHierBinding)tableModel.getWrappedData();
DCIteratorBinding dciter = adfModel.getDCIteratorBinding();
NavigatableRowIterator nav=dciter.getNavigatableRowIterator();
Row newRow = nav.createRow();
newRow.setNewRowState(Row.STATUS_INITIALIZED);
Row currentRow = nav.getCurrentRow();
int currentRowIndex = nav.getRangeIndexOf(currentRow);
nav.insertRowAtRangeIndex(currentRowIndex+1, newRow);
dciter.setCurrentRowWithKey(newRow.getKey().toStringFormat(true));
return null;
}
***************************
Approach 3
public String save() {
String amDef = "model.AppModule";
String config = "AppModuleLocal";
ApplicationModule am = Configuration.createRootApplicationModule(amDef, config);
ViewObject vO=am.findViewObject("StudentVO1");
StudentVORowImpl studentRow=(StudentVORowImpl)vO.createRow();
studentRow.setRoll("0001");
studentRow.setName("Success");
vO.insertRowAtRangeIndex(1, studentRow);
am.getTransaction().commit();
return "back";
}