Jsf 2 使用primefaces显示隐藏数据表
我有个问题,还找不到解决办法。我有一个.xhtml页面,在这个页面中,我有一些输入字段和一个提交按钮,当我单击提交按钮时,数据表将显示在下面,但我希望在页面首次加载时,该表不会显示。下面是我的.xhtml代码:Jsf 2 使用primefaces显示隐藏数据表,jsf-2,primefaces,datatable,Jsf 2,Primefaces,Datatable,我有个问题,还找不到解决办法。我有一个.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://x
<!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>
在第一次加载页面时,我将showTable=false(在setShowTable()方法中),这样layDataTable就不会显示(rendered=“#{auditLogMB.showTable}”),在“Show”按钮上,我调用动作“#{auditLogMB.displayTable}”(在这个方法中,showTable将为true),因此呈现的属性现在为“true”,但这张桌子还没有装好。有人能解释一下我的代码中是否有bug吗
谢谢大家! 不能更新以前未渲染过的组件。您必须更新周围的容器。备选方案:使用javascript设置display属性以显示/隐藏组件,如果这可能足够的话。可能重复感谢你们两位,将表嵌套在h:panelGroup中解决了我的问题
@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;
}
}