PrimeFaces用List< Object []>填充DataTable [英] PrimeFaces filling DataTable with List<Object[]>
问题描述
对象数组定义每个列的值,对于列表,该列表由本机sql查询的结果填充。 expample Object [0]是第一列的值。
我的dataTable类似于
< p:dataTable id =dataTable1RQvar =itemvalue =#{reportQuestionMBean.dataTable}>
< p:column id =modelHeader>
< f:facet name =header>
市场
< / f:facet>
< h:outputText value =#{reportQuestionMBean.market.name}/>
< / p:column>
< p:column>
< f:facet name =header>
表单
< / f:facet>
< h:outputText value =#{reportQuestionMBean.form.name}/>
< / p:column>
< p:column>
< f:facet name =header>
问题
< / f:facet>
< h:outputText value =#{item}/>
< / p:column>
< / p:dataTable>
我想填写列问题,但我无法到达对象数组的索引列表。如果它是一个特定的类而不是Object [],那么可以通过实现这样的方式来容易地填充这个
< h: outputText value =#{item.name}/>
但它不是。所以如果你知道如何达到一个列表中的数组的索引,你的帮助将使我得到预期。
谢谢。
您可以使用EL中的括号符号 []
通过索引访问数组项。
所以,这应该是
h:outputText value =#{item [0]}/>
I am trying to fill a DataTable with a List that was filled by a result queried by a native sql.
Object array defines the value of each columns, for expample Object[0] is the value of the first column.
My dataTable is something like this
<p:dataTable id="dataTable1RQ" var="item" value="#{reportQuestionMBean.dataTable}">
<p:column id="modelHeader">
<f:facet name="header">
Market
</f:facet>
<h:outputText value="#{reportQuestionMBean.market.name}" />
</p:column>
<p:column>
<f:facet name="header">
Form
</f:facet>
<h:outputText value="#{reportQuestionMBean.form.name}" />
</p:column>
<p:column>
<f:facet name="header">
Question
</f:facet>
<h:outputText value="#{item}" />
</p:column>
</p:dataTable>
I want to fill the column 'Question' but I cannot reach the index of the Object array in the List. If it was a specific class instead of Object[], it would be easy to fill by implementing like this
<h:outputText value="#{item.name}" />
But it is not. So if you know how to reach the index of an array in a list, your help will make me preciated.
Thanks.
You can use the brace notation []
in EL to access an array item by an index.
So, this should do
<h:outputText value="#{item[0]}" />
这篇关于PrimeFaces用List< Object []>填充DataTable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!