Sunday, November 30, 2014

ADF: Add New row after Selected row

ADF 11g 11.1.1.7.0

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 =
            (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
        DCIteratorBinding dciter =
            (DCIteratorBinding)DCbindings.get("EmployeesVO1Iterator");
        //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
        newRow.setNewRowState(Row.STATUS_INITIALIZED);
        //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
        rsi.setCurrentRow(newRow);
    }

No comments:

Post a Comment

Provide your thoughts !