I'm have a problem and can't find the solution yet. I have a .xhtml page, in this page, I have some input fields and a submit button, when I click submit button, a datatable will be displayed under, but I want that at the page first load time, the table will not show. Here my .xhtml code:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:a="http://xmlns.jcp.org/jsf/passthrough"
xmlns:p="http://primefaces.org/ui"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Report Page</title>
</h:head>
<h:body>
<h:form>
<p:panelGrid columns="6" style="width: 100%">
<f:facet name="header">Report input</f:facet>
<h:outputLabel value="User name:" />
<p:inputText id="userName" value="#{auditLogCriteria.userNameFilter}"></p:inputText>
<h:outputLabel value="Impacted user:" />
<p:inputText id="impactedUser" value="#{auditLogCriteria.impactedUserFilter}"></p:inputText>
<h:outputLabel value="Enrollee id:" />
<p:inputText id="enrolleeId" value="#{auditLogCriteria.enrolleeIdFilter}"></p:inputText>
<h:outputLabel value="Action type:" />
<p:selectCheckboxMenu id="actionTypes" value="#{auditLogCriteria.actionTypes}" label = "Action types">
<f:selectItems value="#{auditActionTypeView.actionTypes}"/>
</p:selectCheckboxMenu>
<h:outputLabel value="Start date:" />
<p:calendar id="startDate" value="#{auditLogCriteria.startDate}"/>
<h:outputLabel value="End date:" />
<p:calendar id="endDate" value="#{auditLogCriteria.endDate}"/>
<h:outputLabel value="Order column:" />
<p:selectOneMenu id="orderColumn" value="#{auditLogCriteria.orderColumn}">
<f:selectItem itemLabel="Select order column" itemValue="" noSelectionOption="true" />
<f:selectItems value="#{auditLogOrderColumnView.orderColumns}"/>
</p:selectOneMenu>
<p:commandButton value="Show" id="showReport" update="lazyDataTable" action="#{auditLogMB.displayTable}"/>
</p:panelGrid>
<p:dataTable id="lazyDataTable" value="#{auditLogMB.allRecords}" var="record" paginator="true" rows="100" selectionMode="single"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="50,100,150" lazy="true" rendered="#{auditLogMB.showTable}">
<p:column>
<f:facet name="header">Log id</f:facet>
<h:outputText value="#{record.auditLogId}" />
</p:column>
<p:column>
<f:facet name="header">User name</f:facet>
<h:outputText value="#{record.userName}" />
</p:column>
<p:column>
<f:facet name="header">Timestamp</f:facet>
<h:outputText value="#{record.timeStamp}" />
</p:column>
<p:column>
<f:facet name="header">Action type</f:facet>
<h:outputText value="#{record.actionType}" />
</p:column>
<p:column>
<f:facet name="header">Impacted user</f:facet>
<h:outputText value="#{record.impactedUser}" />
</p:column>
<p:column>
<f:facet name="header">Enrollee id</f:facet>
<h:outputText value="#{record.enrolleeId}" />
</p:column>
<p:column>
<f:facet name="header">Current data</f:facet>
<h:outputText value="#{record.currentData}" />
</p:column>
<p:column>
<f:facet name="header">New data</f:facet>
<h:outputText value="#{record.newData}" />
</p:column>
<p:column>
<f:facet name="header">Result code</f:facet>
<h:outputText value="#{record.resultCode}" />
</p:column>
<p:column>
<f:facet name="header">Result message</f:facet>
<h:outputText value="#{record.resultMessage}" />
</p:column>
</p:dataTable>
</h:form>
</h:body>
</html>
And here is some related code in my bean:
@ManagedBean
@ViewScoped
public class AuditLogMB implements Serializable {
private static final long serialVersionUID = 1L;
private boolean showTable;
public boolean getShowTable() {
return this.showTable;
}
@PostConstruct
public void setShowTable() {
this.showTable = false;
}
public void displayTable() {
showTable = true;
records = null;
}
}
At page first load, I set showTable = false (at setShowTable() method), so layDataTable will not displayed (rendered="#{auditLogMB.showTable}"), at "Show" button, i call action "#{auditLogMB.displayTable}" (in this method, showTable will be true), so the rendered attribute will now "true", but the table is still not load. Can anyone explain if there is any bug in my code.
Thank you!