2

I have an ArrayList from a Bean :

...
public ArrayList<String[]> getArticleList() {
    ...
}
...

I need to print these values (with getter method) by using EL on JSF2 (such as #{bean.articlesLage}

How can I do this? Cheers

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
markzzz
  • 47,390
  • 120
  • 299
  • 507

2 Answers2

7

I don't remember if JSF supports arrays, however if you can convert your ArrayList<Array> to ArrayList<ArrayList<String>>, then something like this should work

<ui:repeat value="#{bean.articleList}" var="t">
   <ui:repeat value="#{t}" var="s">
      #{s}
   </ui:repeat>
</ui:repeat>
Shervin Asgari
  • 23,901
  • 30
  • 103
  • 143
  • Nice One. And if i want to select the index 2 for each string[]? – markzzz Dec 01 '10 at 14:53
  • What do you mean select the index 2? – Shervin Asgari Dec 01 '10 at 14:59
  • I mean : my `ArrayList` has more `String[]`. If my first `String[]` in the arraylist is `[hello, im, marco]` and the second is `[how, are, you]` I would like to print values `marco` and `you` (which are at the 2° position for each `String[]`. – markzzz Dec 01 '10 at 15:06
  • The `#{s}` refers to the individual `String` item of `String[]`. The `#{t}` refers to individual `String[]` item of the `List`. So you want to get rid of nested `ui:repeat` and use `#{t[2]}` instead. – BalusC Dec 01 '10 at 16:16
  • What about If I want to edit values of ArrayList by putting `h:inputText` inside `ui:repeat`? http://stackoverflow.com/questions/19395621 – Kishor Prakash Oct 16 '13 at 05:25
2

You can use a nested ui:repeat or a nested datatable like this with your current model ArrayList :

<h:dataTable value="#{bean.articleList}" var="row">
    <h:column>
        <f:facet name="header">
            <h:outputText value="COL" />
        </f:facet>
        <h:dataTable value="#{row}" var="nested_row">
            <h:column>
            <f:facet name="header">
                <h:outputText value="COL" />
            </f:facet>
                <h:outputText value="#{nested_row}" />
            </h:column>
    </h:dataTable>          
    </h:column>
</h:dataTable>
ddewaele
  • 22,363
  • 10
  • 69
  • 82