java PrimeFaces 用 List<Object[]> 填充 DataTable

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11484963/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 05:17:41  来源:igfitidea点击:

PrimeFaces filling DataTable with List<Object[]>

javajsfdatatableprimefaces

提问by Egemen Hamut?u

I am trying to fill a DataTable with a List that was filled by a result queried by a native sql.

我正在尝试使用由本机 sql 查询的结果填充的列表填充 DataTable。

Object array defines the value of each columns, for expample Object[0] is the value of the first column.

对象数组定义了每一列的值,例如 Object[0] 是第一列的值。

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

我想填充“问题”列,但无法到达列表中对象数组的索引。如果它是一个特定的类而不是 Object[],那么通过这样实现就很容易填充

<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.

谢谢。

回答by BalusC

You can use the brace notation []in EL to access an array item by an index.

您可以[]在 EL 中使用大括号表示法通过索引访问数组项。

So, this should do

所以,这应该做

<h:outputText value="#{item[0]}" />