Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iterate through List<String> using JSF 2

Tags:

jsf

jsf-2

I have this java code.

List<String> myList = new ArrayList<String>();
myList.add("Hello");
myList.add("World");

I need to loop through the list to display those values in a webpage. I thought of using a dataTable but I don't know how to retrieve each entry on the list.

Ideas? Thanks!

like image 823
Nacho321 Avatar asked Aug 09 '13 15:08

Nacho321


1 Answers

You can use <ui:repeat>:

<ui:repeat value="#{bean.myList}" var="value">
    #{value} <br />
</ui:repeat>

If you're not sure if you should use <h:dataTable> or <ui:repeat>, you can check an example that mkyong provides here: JSF 2 repeat tag example

In short: <h:dataTable> renders a <table> HTML component, while <ui:repeat> gives you the flexibility to choose how to display the data.

like image 74
Luiggi Mendoza Avatar answered Oct 18 '22 21:10

Luiggi Mendoza