Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
182 views
Welcome To Ask or Share your Answers For Others

1 Answer

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]}" />

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...