根据列名称列表在h:dataTable中创建h:column组件 [英] Create h:column components inside h:dataTable based on a list of column names
问题描述
我正在尝试使用两个列表创建一个<h:dataTable>
.一个列表包含列名,另一列表包含将填充表的数据.我需要包含列名的列表,因为第二个中的数据具有比我想显示的更多的属性.我该如何实现?
I'm trying to create a <h:dataTable>
using two lists. One list contains the column names and the other one contains the data that will populate the table. I need the list containing the column names because the data in the second one has more attributes than I'd like to display. How can I achieve this?
推荐答案
是的,如果使用<c:forEach>
遍历列名并生成<h:dataTable>
所需的<h:column>
组件,则可以.您可以在EL中使用大括号符号[]
将列名用作动态" bean属性名(甚至用作Map
键).
Yes, you can if you use <c:forEach>
to iterate over the column names and generate the <h:column>
components necessary for <h:dataTable>
. You can use the brace notation []
in EL to use the column name as a "dynamic" bean property name (or even as a Map
key).
<h:dataTable value="#{bean.rows}" var="row">
<c:forEach items="#{bean.columnNames}" var="columnName">
<h:column>#{row[columnName]}</h:column>
</c:forEach>
</h:dataTable>
这篇关于根据列名称列表在h:dataTable中创建h:column组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!