【发布时间】:2020-05-12 12:52:37
【问题描述】:
所以我有 2 个列表,其中一个来自数据库,第二个稍后用传递的名称更新。第一个列表在用户显示页面时通过@PostConstruct 方法获取,第二个列表针对来自etiquette 的每个name 值进行更新。
showClients.java bean 与 @ViewScoped 值
private List<Etiquette> etiquetteList;
private List<Client> clientList;
...getters and setters
@PostConstruct
public void init() {
HttpSession session = SessionUtil.getSession();
User user = (User) session.getAttribute("user");
etiquetteList = etiquetteDAO.getAllEtiquettes(user);
System.out.println(etiquetteList);
}
public List<Client> showClientsForEtiquette(String etiquetteName) {
clientList = clientDAO.findClientsByEtiquetteName(etiquetteName);
System.out.println(clientList);
return clientList;
}
目前一切正常。我已经etiquetteList 和clientList 充满了数据。自从我开始使用这些数据进行调试以来,我已经这样做了
<h:form>
<ui:repeat value="#{showClients.etiquetteList}" var="etiquette">
<p:panel id="horizontal" header="#{etiquette.name}" toggleSpeed="100" toggleable="true" toggleOrientation="vertical" collapsed="true" >
<p:panelGrid columns="3" layout="grid" styleClass="showcase-text-align-center" >
<h:outputText value="Client name"/>
<h:outputText value="Client email"/>
<h:outputText value="Show details"/>
</p:panelGrid>
<p:panelGrid id="clientData" styleClass="showcase-text-align-center">
<ui:repeat value="#{showClients.clientList}" var="client">
<p:panelGrid columns="3" layout="grid" styleClass="showcase-text-align-center" >
<h:outputText value="#{client.name}"/>
<h:outputText value="#{client.email}"/>
<p:commandButton value="details" type="button" onclick="PF('clientDetails').show();" >
<f:param name="client" value="client"/>
</p:commandButton>
</p:panelGrid>
</ui:repeat>
</p:panelGrid>
</p:panel>
</ui:repeat>
</h:form>
但是这种方式很笨拙,我想以非常不同的方式显示这些数据。我想使用PrimeFaces 库在dataTable 中显示它 - 我想要可切换的功能(可切换方式,您只需单击礼仪名称并显示/隐藏客户信息)、分页、延迟获取等. 就我所尝试的实现而言,我已经做到了。
<h:form id="groupForm">
<h:form>
<p:dataTable value="#{showClients.etiquetteList}" var="e" sortBy="#{e.name}" expandedRow="false" expandableRowGroups="true" rows="10"
paginator="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
currentPageReportTemplate="{startRecord}-{endRecord} of {totalRecords} records"
rowsPerPageTemplate="5,10,15" >
<p:headerRow>
<f:facet name="header">
<p:column colspan="3">
<h:outputLabel value="#{e.name}" />
</p:column>
</f:facet>
</p:headerRow>
<p:column colspan="3" style="margin: 20px 0;" >
<p:dataTable value="#{showClients.showClientsForEtiquette(e.name)}" var="c" lazy="true" expandedRow="false">
<p:column headerText="Email">
#{c.email}
</p:column>
<p:column headerText="Szczegóły">
<p:commandButton value="Szczegóły"/>
</p:column>
<p:column headerText="Usuń" >
<p:commandButton value="Usuń"/>
</p:column>
</p:dataTable>
</p:column>
</p:dataTable>
</h:form>
这就是我想要显示我的数据的方式。我该如何处理?我已经读到您无法设置表头,因为表是逐行生成的,并且数据还没有显示为表头。有什么解决方法吗?另外,如何使我的表格行(此行带有 e.name )可切换?在dataTable 中使用一些panelGrid?
+----------------------------------------------------+
| e.name (value) |
+-----------------------------------------------------
| Email (string) | Detail (string) | Delete (string) |
| c.email | button | button |
【问题讨论】:
-
使用 PrimeFaces 'p:overlay'?
-
但是我想不断地在我的应用程序的子页面上显示该表格,并使用 p:overlay 作为客户端的详细信息值,那不是问题吗?
-
如果你想使用子页面然后使用子页面......这都是简单的主从功能。但在我看来,这个标题完全不相关......见stackoverflow.com/questions/8459903/…。请澄清您的问题
-
但是我的问题是相关的...我想循环遍历 2 个列表并以某种指定的方式将数据显示为 dataTable 给用户,但我不知道如何实现我指定的
-
那么我的评论是:“如果你使用纯 java 和
System.out.println来显示,你会怎么做,你必须改变模型服务器端。在这里做同样的事情...
标签: jsf