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

2 Answers 2

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>
Sign up to request clarification or add additional context in comments.

5 Comments

Nice One. And if i want to select the index 2 for each string[]?
What do you mean select the index 2?
I mean : my ArrayList<String[]> 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[].
The #{s} refers to the individual String item of String[]. The #{t} refers to individual String[] item of the List<String[]>. So you want to get rid of nested ui:repeat and use #{t[2]} instead.
What about If I want to edit values of ArrayList by putting h:inputText inside ui:repeat? stackoverflow.com/questions/19395621
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>

2 Comments

Why rich? richfaces is not tagged
Was an example using the RichFaces component, The std JSF datatable (prefix h:) can do the same thing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.