Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use <ui:repeat> to iterate over a nested list?

Using JSF 2.0, I need to display a table wherein each row contains a link which opens a popup. I have two models: A which has id and List<B> properties and B which has id and name properties. In my backing bean, I have a List<A> property. In my view, I am using <ui:repeat> to iterate over List<A>.

The requirement is, depending on the row that the user clicks, the corresponding List<B> of A needs to be displayed. However, the <ui:repeat> does not accept a nested list to be assigned in the var attribute. Hence, I need to do a lot of workarounds which is not efficient.

How do I efficiently solve this problem?

like image 443
user2228591 Avatar asked Mar 31 '13 05:03

user2228591


1 Answers

What you need is to nest another <ui:repeat> tag in your outer iteration:

<ui:repeat value="#{bean.listOfA}" var="a">
    ...
    <ui:repeat value="#{a.listOfB}" var="b">
        ...
    </ui:repeat>
</ui:repeat>

The only thing left that is worth noting is that nested <ui:repeat> tags used to have problems with state management until Mojarra 2.1.15 version (details in jsf listener not called inside nested ui:repeat and in many not so recent questions and their answers), which could result in action listeners not called, etc. but if you're currently on the latest Mojarra JSF implementation - just skip this part altogether.

like image 187
skuntsel Avatar answered Sep 21 '22 18:09

skuntsel