Wednesday, June 1, 2011

Insert row at the End of Table @ADF

In order to add a row at the end of the table and make the inserted row to be current row, we can write following code on the action of a button having partial submit property set to true:

public void insertRowAtLast()
{
   CollectionModel cmodel= (CollectionModel)table.getValue();
   JUCtrlHierBinding adfmodelbind= (JUCtrlHierBinding) cmodel.getWrappedData();
   DCIteratorbinding itr=adfmodelbind.getDCIterator();
   
   Row row_last=itr.getNavigatableRowIterator().last();
   Row row_new=itr.getNavigatableRowIterator().createRow();
   row_new.setNewRowState(Row.State_INITIALIZED);
  
   int lastrow_index=itr.getNavigatableRowIterator().getRangeIndexOf(row_last);
   itr.getNavigatbleRowIterator().insertRowAtRangeIndex(lastrow_index+1,row_new);
   itr.setCurrentRowWithKey(row_new.getKey().toStringFormat(true));


  AdfFacesContext.getCurrentInstance().addPartialTarget(table);
}


To make the newly inserted row to be visible after table refreshes, set the DisplayRow attribute of the table to selected.

No comments:

Post a Comment