Search code examples
jsfhtml-listsuirepeat

How can I show my 2D arrayList using the <ui:repeat> in JSF


I can show the objects of the plain arrayList.

ArrayList<Object>names;

<ui:repeat  value="#{bean.names}" var="t">
                          <ul>
                              <li  render="" id="hm">  

                                   <a>#{t.name}</a>
                             </li>
                          </ul></ui:repeat>

But if I have List<ArrayList<Object>> names2 = new ArrayList<ArrayList<Object>>();

I tried to use nested <ui:repeat> or <c:forEach> but it doesn't work. I dont want to use data tables since I want to display them as a list.

E.g I tried to do this but it doesn't work, neither with <ui:repeat>, is it possible what I try to do?

 <ul>

                                        <li> 

                                              <c:forEach items="#{bean.names2}" var="row">
                                                <c:forEach items="#{row}" var="nested_row">

                                                    <c:forEach items="#{nested_row}" var="t">
                                                        <a>#{t.name}</a>
                                                    </c:forEach>

                                                </c:forEach>                                                
                                              </c:forEach>             

                                        </li>

                                    </ul>

Solution

  • Your code attempt with three <c:forEach>s expects a 3D array/list. Get rid of that one <c:forEach> too much.

    <c:forEach items="#{bean.names2}" var="row">
        <c:forEach items="#{row}" var="nested_row">
            #{nested_row.name}
        </c:forEach>
    </c:forEach>
    

    The same should work for <ui:repeat>.