Add the row at the end of ViewObject’s current RowSet in ADF

Sharing is Caring

This post is about adding a row at the end of ViewObject’s current rowset without using table or any other UI components binding

Here I have a Department ViewObject (HR Schema), dropped as a table on the page and a button to add a new row, this button calls a method from the model using the binding layer of ADF framework, you can learn more about ADF bindings here


The code in AMImpl to add a row at the end of ViewObject’s current RowSet

    /**
     * Method to add row at the end of viewObject
     */
    public void addRowAtEnd() {
        //Get ViewObject
        ViewObjectImpl deptVo = this.getDepartmentsVO1();
        //Get current data RowSetIterator
        RowSetIterator rsi = deptVo.getRowSetIterator();
        //Get last Row of current Iterator
        Row lRow = rsi.last();
        //Get index of the last row
        int lrIndex = rsi.getRangeIndexOf(lRow);
        //Create a new row
        Row nRow = rsi.createRow();
        //Initialize that row
        nRow.setNewRowState(Row.STATUS_INITIALIZED);
        //Add row in last of current rowset
        rsi.insertRowAtRangeIndex(lrIndex + 1, nRow);
        //Set newly created row as current row
        rsi.setCurrentRow(nRow);
    }

 

Bean Code to call Model layer method using ADF bindings

    /**Generic Method to get BindingContainer of current page,
     */
    public BindingContainer getBindingsCont() {
        return BindingContext.getCurrent().getCurrentBindingsEntry();
    }

/**
 * Generic Method to execute operation
 * */
public OperationBinding executeOperation(String operation) {
OperationBinding createParam = getBindingsCont().getOperationBinding(operation);
return createParam;
}

/**Method to add new row
 * @param actionEvent
 */
public void addNewRowAction(ActionEvent actionEvent) {
executeOperation("addRowAtEnd").execute();
}

Now run and check Application, Click on Add Row button and see that new row is added at the end of the table (at end of current rowset of viewObject) .

row at the end of ViewObject's current RowSet

Cheers 🙂 Happy Learning

Related Posts

An Oracle ACE, Blogger, Reviewer, Technical Lead working on Oracle ADF

Leave a Reply

Your email address will not be published. Required fields are marked *