I have a small table with about 200 rows. I use PrimeFaces dataTable to display them, but the rendering is very slow (about 5-6 seconds to fully displayed). Below is my code:
BudgetSource.xhtml
Code: Select all
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:form id="budgetSourceFrm">
<div>
<p:outputLabel value="Budge Source" style="font-weight: bold" />
</div>
<div style="margin-top: 5px">
<p:commandButton value="Add" onclick="PF('newBudgetSourceDlg').show()" icon="pi pi-plus" style="text-align: center; margin-right: 30px;" rendered="#{businessBean.task == 8}"/>
<p:commandButton value="Edit" onclick="PF('editBudgetSourceDlg').show()" icon="pi pi-pencil" style="text-align: center; margin-right: 30px;" rendered="#{businessBean.task == 8}"/>
<p:commandButton value="Delete" action="#{budgetSourceBean.removeSelected}" styleClass="ui-button-danger" icon="pi pi-trash" style="text-align: center; margin-right: 30px;" oncomplete="PF('budgetSourcesTable').filter()" process="@this" rendered="#{businessBean.task == 8}">
<p:confirm header="Confirm" message="Delete the record?" icon="pi pi-exclamation-triangle" />
</p:commandButton>
<p:commandButton value="Print" icon="pi pi-print" style="text-align: center; margin-right: 30px;" rendered="#{businessBean.task == 8}"/>
</div>
<p:dataTable id ="budgetSources" emptyMessage="" draggableColumns="true" resizableColumns="true" resizeMode="expand" var="bs" widgetVar="budgetSourcesTable"
value="#{budgetSourceController.findAll(sessionInfoBean.currentDatabase)}" rendered="#{businessBean.task == 8}"
filteredValue="#{budgetSourceBean.filteredBudgetSources}" selectionMode="single" sortBy="#{bs.budgetSourceCode}" sortMode="single"
selection="#{budgetSourceBean.selectedBudgetSource}" rowKey="#{bs.budgetSourceCode}" showGridlines="true"
paginator="true" rows="6" paginatorPosition="bottom"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
currentPageReportTemplate="{startRecord}-{endRecord} of {totalRecords} record.">
<p:ajax event="rowSelect" listener="#{budgetSourceBean.rowSelect}"/>
<p:ajax event="rowUnselect" listener="#{budgetSourceBean.rowUnSelect}"/>
<p:column headerText="Code" groupRow="true" filterBy="#{bs.budgetSourceCode}" filterMatchMode="contains" sortBy="#{bs.budgetSourceCode}" sortOrder="asc" style="text-align: left">
<h:outputText value="#{bs.budgetSourceCode}" />
</p:column>
<p:column headerText="Name" filterBy="#{bs.budgetSourceName}" filterMatchMode="contains" sortBy="#{bs.budgetSourceName}" style="text-align: left">
<h:outputText value="#{bs.budgetSourceName}" />
</p:column>
<p:column headerText="Type" filterBy="#{bs.budgetSourceProperty}" filterMatchMode="contains" sortBy="#{bs.budgetSourceProperty}" style="text-align: center">
<h:outputText value="#{bs.budgetSourceProperty == 0 ? 'Domestic' : 'Foreign'}" style="text-align: left"/>
</p:column>
<p:column headerText="Used" style="text-align:center">
<f:facet name="filter">
</f:facet>
<p:selectBooleanCheckbox value="#{bs.active}" disabled="true"/>
</p:column>
</p:dataTable>
</h:form>
</p:dialog>
</ui:composition>
Code: Select all
package com.spf.ibigtime.jpa.dao;
import com.spf.ibigtime.entities.Budgetsource;
import java.util.List;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
/**
*
* @author charlie
*/
@Named
@RequestScoped
public class BudgetSourceController extends Dao<Budgetsource> {
public List<Budgetsource> findAll(String multitenancyIdentifier) {
return getEntityManager(multitenancyIdentifier).createNamedQuery("Budgetsource.findAll", Budgetsource.class)
.getResultList();
}
public Budgetsource findByBudgetSourceID(String budgetSourceID, String multitenancyIdentifier) {
return getEntityManager(multitenancyIdentifier).createNamedQuery("Budgetsource.findByBudgetSourceID", Budgetsource.class).setParameter("budgetSourceID", budgetSourceID)
.getSingleResult();
}
public Budgetsource findByBudgetSourceCode(String budgetSourceCode, String multitenancyIdentifier) {
return getEntityManager(multitenancyIdentifier).createNamedQuery("Budgetsource.findByBudgetSourceCode", Budgetsource.class).setParameter("budgetSourceCode", budgetSourceCode)
.getSingleResult();
}
}
PrimeFaces version 11, MySQL server 10.4.21, Glassfish server 5, Jakarta EE 8