Load a large volume of data into a dataTable

1

I'm having the following problem, I can load the data in my dataTable but it gets very heavy, even the IDE of a locked one. How could I fix this problem? I heard about Lazy but I did not understand how I can implement it.

Listing method:

public void listar() {
        try {
            if (listaBeneficiario == null) {
                listaBeneficiario = new ArrayList<>();
            }

            System.err.println("Metodo Listar" + listaBeneficiario);

            BeneficiarioDAO beneficiarioDAO = new BeneficiarioDAO();
            listaBeneficiario = beneficiarioDAO.buscar();

        } catch (Exception e) {
            FacesUtil.adicionarMsgErro("Erro ao listar tarefas: "
                    + e.getMessage());
        }

    }
    
asked by anonymous 04.08.2015 / 13:14

1 answer

0

You can use paging in your dataTable. Example:

<rich:dataTable value="#{seuBB.lista}" var="obj"
    id="tabela" noDataLabel="Tabela vazia"
    rows="10">

    <rich:column>
        <f:facet name="header">
            <h:outputText value="ID"
        </f:facet>
        <h:outputText value="#{obj.id}" />
    </rich:column>

    ... outras colunas ...

    <f:facet name="footer">
        <rich:dataScroller renderIfSinglePage="false" />
    </f:facet>
</rich:dataTable>

So you define how many rows per page your table will have rows="10" and there in footer , this dataScroller promotes pagination if there is more than one page. / strong> There are two types of mapping loads @OneToMany . @OneToMany(fetch=FetchType.LAZY) and @OneToMany(fetch=FetchType.EAGER) .
Read a little about this here

Briefly,

  

The idea of Lazy is not to bring unnecessary objects


While EAGER always brings all objects related to that class, LAZY only comes when you explicitly load them, using a JOIN FETCH in the search (when using HQL) or createAlias , using Criteria .

EDIT: The Lazy you are referencing is lazy from dataTable, right ?? From what I've seen, this implementation is only possible with the primefaces dataTable ... Here at showcase has an example of how to do this

    
04.08.2015 / 13:28