Wednesday, May 14, 2014

How to insert the row at a given location in the table in Oracle ADF?

import oracle.adf.model.BindingContext;
import oracle.binding.BindingContainer;
import oracle.jbo.NavigatableRowIterator;
import oracle.jbo.Row;
import oracle.jbo.uicli.binding.JUCtrlHierBinding;
import oracle.adf.model.binding.DCIteratorBinding;

public String createEmployeeAtBottom() {
        BindingContainer bc = BindingContext.getCurrent().getCurrentBindingsEntry();
        JUCtrlHierBinding hierBinding = (JUCtrlHierBinding)bc.get("EmployeesView");
        DCIteratorBinding dciter = hierBinding.getDCIteratorBinding();
        NavigatableRowIterator rowIter = dciter.getNavigatableRowIterator();
        Row newRow = rowIter.createRow();
        newRow.setNewRowState(Row.STATUS_INITIALIZED);

        Row lastRow = rowIter.last();
        int lastRowIndex = rowIter.getRangeIndexOf(lastRow);

        //Modify this step as per requirement and as described below
        rowIter.insertRowAtRangeIndex(lastRowIndex + 1, newRow);
        dciter.setCurrentRowWithKey(newRow.getKey().toStringFormat(true));
        return null;
    }

Insert the row at the beginning of the table
rowIter.insertRowAtRangeIndex(0, newRow);

Create a new row before the currently selected row
rowIter.insertRow(newRow);

Create a new row after the currently selected row
Row currentRow = rowIter.getCurrentRow();
int currentRowIndex = rowIter.getRangeIndexOf(currentRow);
rowIter.insertRowAtRangeIndex(currentRowIndex+1, newRow);


No comments:

Post a Comment