Tuesday, August 2, 2011

ADF : Refreshing a service backed table and keeping the correct item highlighted

Make sure your table has  displayRow="selected" set.

<af:table value="#{bindings.CustomerVO.collectionModel}" var="row"
  rows="#{bindings.CustomerVO.rangeSize}"
  emptyText="#{bindings.CustomerVO.viewable ? 'No data to display.' : 'Access Denied.'}"
  fetchSize="#{bindings.CustomerVO.rangeSize}" rowBandingInterval="0"
  selectedRowKeys="#{bindings.CustomerVO.collectionModel.selectedRow}"
  rowSelection="single" id="table" columnStretching="last" immediate="true"
  displayRow="selected" binding="#{viewScope.customerTypesBean.table}"
  selectionListener="#{viewScope.customerBean.handleTableRowSelection}">

Invoke the following code when your table needs a refresh

//use the name of your tables result iterator here
    DCIteratorBinding iterator = BackingBeanUtils.getIteratorBinding(getResultsIteratorName());
    int rangeIdx = iterator.getCurrentRowIndexInRange();
    int rangePos = iterator.getRangeStart();
    int actualPos = rangeIdx + rangePos;
    String action = "findCustomerVO";
//execute the service here
    ADFUtils.executeOperationBinding(action, new HashMap());
    int rem = actualPos % iterator.getViewObject().getRangeSize();
    int page =
      (int) Math.floor(actualPos / iterator.getViewObject().getRangeSize());
    iterator.getViewObject().setRangeStart(page * iterator.getViewObject().getRangeSize());
    iterator.getViewObject().setCurrentRowAtRangeIndex(rem);

No comments:

Post a Comment