Sunday, November 30, 2014

ADF: Add New row after Selected row

ADF 11g

By default, if you execute 'CreateInsert' operation on selected iterator, a new empty row will be added before selected row. But if you need to add a row after selected row, you need to perform little programmatic logic to achieve it.

Following code block will help you to do it:

    public void addRowAfter(ActionEvent actionEvent) {
        // Add event code here...
        DCBindingContainer DCbindings =
        DCIteratorBinding dciter =
        //access the underlying RowSetIterator
        RowSetIterator rsi = dciter.getRowSetIterator();
        //get handle to the last row
        Row currRow = rsi.getCurrentRow();
        //obtain the index of the last row
        int currRowIndex = rsi.getRangeIndexOf(currRow);
        //create a new row
        Row newRow = rsi.createRow();
        //set new row attribute value
        newRow.setAttribute("PrimaryId", currRowIndex );
        //initialize the row
        //add row to last index + 1 so it becomes last in the range set
        rsi.insertRowAtRangeIndex(currRowIndex + 1, newRow);
        //make row the current row so it is displayed correctly