Performance when generating a JSF table

Asked

Viewed 303 times

0

I’m having a question of how to improve perfomance when generating a table on a page using components JSF and Primefaces.

I am generating a table, after making an SQL query and mapping the object using Hibernate, more specifically, creating a list of objects using ResultTransformer interface.

I realize that this ok, doing TDD, when calling the data processing is fast.

But it has locked the page when it will generate it.

The page code goes like this:

<c:if test="#{bean.pojo.relatorioExtratoLojista != null}">
    <c:forEach var="loja" items="#{bean.buscarLojas()}">
        <c:forEach var="filial" items="#{bean.buscarFilial(loja)}">
            <c:forEach var="atendente" items="#{bean.buscarAtendente(filial)}">
                <c:forEach var="propostaStatus" items="#{bean.buscarPropostaStatus(atendente)}">
                    <p:panelGrid 
                        styleClass="panelGridCenter gridNoBackground" 
                        style="width: 100%; white-space:nowrap;">
                        <f:facet name="header">
                           // colunas do cabeçalho
                        </f:facet>
                        <c:forEach var="propostaCartao" items="#{bean.buscarPropostasCartao(atendente, propostaStatus)}" varStatus="propostaCartaoVarStatus">
                          // dados da tabela
                        </c:forEach>
                    </p:panelGrid>
                    <br/>
                </c:forEach>
            </c:forEach>
        </c:forEach>
    </c:forEach>

Where I put // colunas do cabeçalho the table header is generated, and the comment // dados da tabela has the table data.

The structure is this:

Map<Loja, Map<Filial, Map<Atendente, Map<PropostaStatus, List<PropostaCartao>>>>> mapLoja 

Some of the bean methods are:

public List<Loja> buscarLojas() {
    return new ArrayList<Loja>(this.getPojo().getRelatorioExtratoLojista().keySet());
}

public List<Filial> buscarFilial(Loja loja) {
    Map<Filial, Map<Atendente, Map<PropostaStatus, List<PropostaCartao>>>> mapFilial = this.getPojo().getRelatorioExtratoLojista().get(loja);
    return new ArrayList<Filial>(mapFilial.keySet());
}

public List<Atendente> buscarAtendente(Filial filial) {
    Map<Atendente, Map<PropostaStatus, List<PropostaCartao>>> mapAtendente = this.getPojo().getRelatorioExtratoLojista().
                                                                             get(filial.getLoja()).get(filial);
    return new ArrayList<Atendente>(mapAtendente.keySet());
}

public List<PropostaStatus> buscarPropostaStatus(Atendente atendente) {
    Map<Filial, Map<Atendente, Map<PropostaStatus, List<PropostaCartao>>>> mapFilial = this.getPojo().getRelatorioExtratoLojista().get(atendente.getLoja());
    Map<Atendente, Map<PropostaStatus, List<PropostaCartao>>> mapAtendente = mapFilial.get(atendente.getFilial());
    Map<PropostaStatus, List<PropostaCartao>> mapPropostaStatus = mapAtendente.get(atendente);
    if (NullUtil.isNull(mapPropostaStatus.keySet())) {
        toString();
    }
    return new ArrayList<PropostaStatus>(mapPropostaStatus.keySet());
}

public List<PropostaCartao> buscarPropostasCartao(Atendente atendente, PropostaStatus propostaStatus) {
    Map<Filial, Map<Atendente, Map<PropostaStatus, List<PropostaCartao>>>> mapFilial = this.getPojo().getRelatorioExtratoLojista().get(atendente.getLoja());
    Map<Atendente, Map<PropostaStatus, List<PropostaCartao>>> mapAtendente = mapFilial.get(atendente.getFilial());
    Map<PropostaStatus, List<PropostaCartao>> mapPropostaStatus = mapAtendente.get(atendente);
    return new ArrayList<PropostaCartao>(mapPropostaStatus.get(propostaStatus));
}

I when I put to debugar in the bean, I realized that the method buscarLojas() is called many times, apparently more than should.

I would like to know what I can do to improve the performance, since I have query to precisely decrease the amount of data.

  • Hello, I noticed that there is no Lazyload, in case, everything is found and shown at once, check? If yes, how many records are presented?

  • @Ricardorodriguesdefaria this is a complicated question, because they can vary a lot, because they are data where the user can choose parameters in the filter as dates among other things, but can be displayed for example more than 10 thousand records.

  • 1

    It may be that the problem ai, is not in select, but in page rendering, even with purely html element, 10 thousand records are able to lock your browser considerably, in the case of JSF, this is certainly worse since there is still a whole DOM management. I advise to create a pagination, will probably solve your problem.

  • @Ricardorodriguesdefaria I am not using Datatable, it has how to make pagination without using datatable.

  • In the case of JSF it is more difficult, because the component of the data table takes care of abstracting the calls to the next page, previous page and things like, possible is, but I can’t guide you.

  • @Ricardorodriguesdefaria, thank you and I will leave open for other suggestions.

  • @Macario1983, why, once you make use of Primefaces, you do not use the datatable component?

  • @Weslleytavares because I wanted to use repeat loop inside the data part of the columns and with the datatable didn’t work.

  • @Ricardorodriguesdefaria I switched the component to ui:repeat and performance improved considerably.

  • You tried to use the p:treeTable?

  • @Weslleytavares sorry, but I do not know this component, what worries me is that there are so many generated tables that will generate many things...

  • 1

    You’ll have to look at the documentation (starting with the showcase) of Primefaces. There you will see the implementation of the concept of treeTable and pagination in a much more enlightening way (since it has a lot of code to analyze).

  • That good guy, I believe that if paging completely solves the problem.

Show 8 more comments

1 answer

2

To make official an answer.

The main problem in question is the lack of use of Lazyload and not in select. Page rendering, even with purely html element, are able to lock your browser considerably (you can test with tables above 500 lines), in the case of JSF, the result is even worse, since there is still a whole DOM management and an infinite sequence of requests for page construction.

Showing all the information in a table, which has no fixed amount of results, sooner or later proves to be a bad architectural choice, since they always tend to grow and generate low performance not only in the view, but a very large load on the server.

Adding a pagination to this list will certainly solve your problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.