我遇到了问题,但还是找不到解决方法。我有一个.xhtml页面,在这个页面中,我有一些输入字段和一个提交按钮,当我点击提交按钮时,会显示一个数据表,但我希望在页面首次加载时,表格不会显示。这是我的.xhtml代码:
<!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>
这是我的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;
}
}
在页面首次加载时,我设置 showTable = false(在setShowTable()方法中),因此layDataTable将不会显示(rendered =“#{auditLogMB.showTable}”),在“显示”按钮,我调用操作“#{auditLogMB.displayTable}”(在此方法中, showTable 将为true),因此渲染的属性现在将为“true”,但表仍未加载。任何人都可以解释我的代码中是否有任何错误。
谢谢!