Flipkart Search

Monday 22 December 2014

Insert new row at the end of an ADF Table

In some of case you may want to insert a new row at the end of the table then this method will come handy.

 public String CreateInsert() { 
DCBindingContainer bindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
        DCIteratorBinding dcIterBind =
            (DCIteratorBinding)bindings.get("EmployeeView1Iterator");
        Row newRow = dcIterBind.getViewObject().createRow();
        newRow.setNewRowState(Row.STATUS_INITIALIZED);
        ViewObject vo = dcIterBind.getViewObject();
        vo.last();
        // to insert row at the end of the table
        vo.next();
        vo.insertRow(newRow);
        return null; 

}

3 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Another way to achieve the above functionality is as follows :

    DCIteratorBinding dciter = (DCIteratorBinding) bindings.get("VOIteratorName");
    if(dciter != null){
    System.out.println("VO IS NOT NULL...");
    }
    else{
    System.out.println("VO IS NULL....");
    }

    RowSetIterator rsi = dciter.getRowSetIterator();
    //get handle to the last row
    Row lastRow = rsi.last();
    //obtain the index of the last row
    int lastRowIndex = rsi.getRangeIndexOf(lastRow);
    //create a new row
    Row newRow = rsi.createRow();
    //initialize the row
    newRow.setNewRowState(Row.STATUS_INITIALIZED);
    //add row to last index + 1 so it becomes last in the range set
    rsi.insertRowAtRangeIndex(lastRowIndex +1, newRow);
    //make row the current row so it is displayed correctly
    rsi.setCurrentRow(newRow);

    ReplyDelete
  3. Thanks for alternate method, I will test and update

    ReplyDelete