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?
– Ricardo Rodrigues de Faria
@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.
– Macario1983
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.
– Ricardo Rodrigues de Faria
@Ricardorodriguesdefaria I am not using Datatable, it has how to make pagination without using datatable.
– Macario1983
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.
– Ricardo Rodrigues de Faria
@Ricardorodriguesdefaria, thank you and I will leave open for other suggestions.
– Macario1983
@Macario1983, why, once you make use of Primefaces, you do not use the datatable component?
– Weslley Tavares
@Weslleytavares because I wanted to use repeat loop inside the data part of the columns and with the
datatable
didn’t work.– Macario1983
@Ricardorodriguesdefaria I switched the component to
ui:repeat
and performance improved considerably.– Macario1983
You tried to use the
p:treeTable
?– Weslley Tavares
@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...
– Macario1983
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).
– Weslley Tavares
That good guy, I believe that if paging completely solves the problem.
– Ricardo Rodrigues de Faria