Question

I am currently trying to implement a lazy loading row expansion. I added a dataGrid in my rowExpansion which value attribute is a method which gets a detailed User from database.

When I debugged this method (userBacking.getDetailedUserById(Long userId)) I recognized that this method is called minimum 5 times when I click on a row. Does anyone know why this method is called so many times? Are there better approaches to implement a lazy loading row Expansion?

<p:dataTable id="myPassengerTable"
                    value="#{userBacking.userTableData}" var="user"
                    selection="#{myRoutesBacking.selectedUser}"
                    selectionMode="single"
                    emptyMessage="no users">

                    <p:ajax event="rowSelect" listener="#{userBacking.onRowSelect}" />

                    <p:ajax event="rowUnselect"
                        listener="#{userBacking.onRowUnselect}" />

                    <p:column styleClass="expand#{user.id}"
                        style="display:none;">
                        <p:rowToggler />
                    </p:column>

                    <p:column >
                        <h:outputText
                            value="#{user.username}" />
                    </p:column>
                    <p:rowExpansion>
                        <p:dataGrid var="detailedUser"
                            value="#{userBacking.getDetailedUserById(user.Id)}"
                            columns="1" rows="1">
                            <p:panelGrid>
                                <p:row>
                                    <p:column>#{detailedUser.firstName} #{detailedUser.lastName}</p:column>
                                </p:row>
                            </p:panelGrid>
                        </p:dataGrid>
                    </p:rowExpansion>
                </p:dataTable>
Était-ce utile?

La solution

Currently (PrimeFaces 6+) p:rowToggler uses Ajax loading, so it's lazy by default. After reading p:rowExpansion gets rendered even though it's not toggled, it seems that this wasn't always the case (up to PrimeFaces 5). So, if possible, just upgrade.

And for the multiple getter calls you should, as already pointed out, check: Why JSF calls getters multiple times.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top