Showing posts with label ViewObjectImpl. Show all posts
Showing posts with label ViewObjectImpl. Show all posts

Friday, March 16, 2012

Displaying the row count for an af:table

Problem

Say you have an af:table based on a view object.  You want to display the number of rows in the table.  Below I describe a couple ways to do it.  The solutions apply to ADF 11.1.1.3.

Solution 1

Create an af:outputText on the page.  Set the value to an EL expression that returns the estimated row count.  Use partialTriggers to refresh the row count when needed.

    <af:outputText value="  Row count: #{bindings.MyVOIterator.estimatedRowCount}"
                              id="ot4" partialTriggers="cb1 cb2"/>

Thanks to the unknown commenter for suggesting this solution.

Solution 2

1. Create a method in a managed bean to return the number of rows.  E.g.

    public int getLineCount() {
        BindingContainer bc = BindingContext.getCurrent().getCurrentBindingsEntry();
        DCBindingContainer bindings = (DCBindingContainer)bc;
        DCIteratorBinding iter = bindings.findIteratorBinding("MyVOIterator");
        return iter.getRowSetIterator().getRowCount();
    }


2.  Make sure there is a binding for the VO iterator ("MyVOIterator") in the page definition.

3. Create an af:outputText on the page.  Set the value to an EL expression that points to the managed bean method.  Use partialTriggers to refresh the row count when needed.

    <af:outputText value="Row count: #{backingBeanScope.MyBean.lineCount}"
                   id="ot2" partialTriggers="cb1 cb2"/>


Note on getRowCount() vs getEstimatedRowCount()

The ViewObjectImpl class has two methods that return the row count: getRowCount() and getEstimatedRowCount().  See this post for a good explanation of the differences.  Briefly:
  • getRowCount() is more accurate, but less performant.
  • getEstimatedRowCount() is potentially less accurate, but more performant. 

Thanks to Richard Ver Steeg for his insights on this topic.