如何在原子数据表中显示可变数量的列 [英] How to display variable number of columns in primefaces datatable
问题描述
我有以下ArrayList
I have the following ArrayList
class Report{
private String manufacturer;
private String color;
private List<Double> revenue;
}
如何在原子datatable上显示它。我尝试使用p:列它不工作。
我在XHTML页面上有以下代码
How can I display it on primefaces datatable. I tried using p:columns it is not working. I have following code on XHTML page
<p:dataTable value="#{tableBean.reportList}" var="report" id="table">
<p:column headerText="Manufacturer">#{report.manufacturer}</p:column>
<p:column headerText="Color">#{report.color}</p:column>
</p:dataTable >
我也尝试过p:columns和ui:repeat。但是我不能达到理想的输出。
I also tried p:columns and ui:repeat. But I am not able to achieve desired output. result.
<p:columns var="amount" value="#{report.revenue}">#{amount}</p:columns>
<ui:repeat var="amount" value="#{report.revenue}">
<p:column headerText="Revenue">#{amount}</p:column>
</ui:repeat>
我需要输出作为具有制造商名称,颜色和所有收入的表格
I need output as a table with manufacturer name, color and all revenues
推荐答案
你的错误是你引用当前迭代的行(< p:dataTable var>
as < p:columns value>
这是不可能的,列的数量不能根据当前迭代的行而变化,只能设置表格范围。< p:columns value>
应该引用一个支持bean中的一个属性,对于一个现实世界的例子,另见这个答案:在JSF2.0中动态创建和填充DataTable 。
Your mistake is that you referenced the currently iterated row (the object behind <p:dataTable var>
as <p:columns value>
. This is not possible. The amount of columns cannot vary based on the currently iterated row. It can only be set table-wide. The <p:columns value>
should reference a property in a backing bean. For a real world example, see also this answer: Creating and populating a DataTable dynamically in JSF2.0.
在特定情况下,您基本上只想使用< ui:repeat>
< p:column>
:
In your particular case, you just basically want to use <ui:repeat>
inside <p:column>
:
<p:dataTable value="#{tableBean.reportList}" var="report">
<p:column>
#{report.manufacturer}
</p:column>
<p:column>
#{report.color}
</p:column>
<p:column>
<ui:repeat value="#{report.revenue}" var="revenue">#{revenue}</ui:repeat>
</p:column>
</p:dataTable>
(如果要以单独的行打印,打印
;或者如果要打印它们的逗号分隔,请使用#{revenue}
之后的< br /> varStatus
)
(if you want to print them in separate lines, print a <br/>
after #{revenue}
; or if you want to print them commaseparated, make use of varStatus
)
或者可能是嵌套表:
<p:column>
<h:dataTable value="#{report.revenue}" var="revenue">#{revenue}</h:dataTable>
</p:column>
这篇关于如何在原子数据表中显示可变数量的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!