user208370
user208370

Reputation: 45

p:rowExpansion gets rendered even though it's not toggled

I have a problem with data in a <p:rowExpansion> being loaded before the row is expanded (which leads to loads of web service requests).

I am using PrimeFaces 5.2. I have a dataTable with lazy loading and pagination. Inside of the table, I have <p:rowToggler> with a <p:rowExpansion>:

<p:dataTable var="order"
             widgetVar="orderTable"
             lazy="true"
             value="#{ordersBean.orders}"
             paginator="true"
             rows="20"
             rowsPerPageTemplate="20,50,100"
             filterDelay="300"
             styleClass="filtered">

    <p:column width="4%">
        <p:rowToggler />
    </p:column>

    <p:column headerText="Order number" width="96%">
        <h:outputText value="#{order.number}" />
    </p:column>

    <p:rowExpansion>
        <h:panelGrid columns="1">
            <h:outputText value="#{order.number}" />
            <h:outputText value="#{order.info}" />

            <h:dataTable var="item" value="#{ordersBean.getItemsInOrder(order.number)}">
                <h:column>
                    <h:outputText value=" #{item.title}" />
                </h:column>
            </h:dataTable>

        </h:panelGrid>
    </p:rowExpansion>
</p:dataTable>

When I first load the page, the getItemsInOrder() method is not called, except for when I expand a row. But if I navigate to page 2 (or if I navigate back to page 1 later) using the paginator, then getItemsInOrder() is called for every row in the outer table. Since I have 20 rows showing, navigating between the pages leads to 20 web service requests (in getItemsInOrder()).

How do I prevent it from calling the getItemsInOrder() method until the row is expanded?

Upvotes: 1

Views: 1822

Answers (1)

Matti M&#228;kitalo
Matti M&#228;kitalo

Reputation: 41

I have the same problem. Until I find a better solution, this is the workaround I am using:

  • register a (DataTable event-) listener on event rowToggle.
  • In the listener, store an identifier of the toggled row. Hint: you can get the row object with event.getData()
  • Instead of directly accessing the data requesting component, write a proxy method in front of it which checks if the requested object belongs to the identifier stored in the listener.

Upvotes: 1

Related Questions