简体   繁体   English

Primefaces数据表动态对象[]

[英]Primefaces datatable dynamic object[]

I want to create a dynamic Primefaces datatable from the result of an sql query that gives me a List<Object[]> as result. 我想根据一个SQL查询的结果创建一个动态的Primefaces数据表,该查询给我一个List<Object[]>作为结果。 The corresponding column names are stored in a List<String> . 相应的列名称存储在List<String>

The columns and the length of the Object[] field should be dynamic. Object[]字段的列和长度应该是动态的。

How to deal with the List<Object[]> in the Datatable? 如何处理数据表中的List<Object[]>

Use <p:columns> . 使用<p:columns> See also PrimeFaces <p:dataTable> showcase - dymamic columns . 另请参见PrimeFaces <p:dataTable>展示-动态列

Provided that you actually mean that you've the data in a List<Object[]> and the columnNames in the same order in List<String> , then this should do: 假设您实际上是说dataList<Object[]> ,而columnNamesList<String>中的顺序相同,则应该这样做:

<p:dataTable value="#{bean.data}" var="item">
    <p:columns value="#{bean.columnNames}" var="columnName" columnIndexVar="i">
        <f:facet name="header">#{columnName}</f:facet>
        #{item[i]}
    </p:columns>
</p:dataTable>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM