本文介绍了如何使用< ui:repeat>遍历嵌套列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用JSF 2.0,我需要显示一个表格,其中每一行都包含一个打开弹出窗口的链接.我有两个模型:具有idList<B>属性的A和具有idname属性的B.在我的后备bean中,我有一个List<A>属性.在我看来,我正在使用<ui:repeat>遍历List<A>.

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>.

要求是,根据用户单击的行,需要显示相应的A.但是,<ui:repeat>不接受要在var属性中分配的嵌套列表.因此,我需要做很多效率不高的解决方法.

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.

如何有效解决此问题?

推荐答案

您需要的是在外部迭代中嵌套另一个<ui:repeat>标签:

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>

唯一值得注意的是,嵌套的<ui:repeat>标签曾经在Mojarra 2.1.15版本之前在状态管理方面存在问题(详细信息请参见中未调用jsf侦听器,并且在许多最近的问题及其答案中也未调用),这可能会导致行动监听器没有被调用,等等.但是,如果您当前正在使用最新的Mojarra JSF实现,则完全跳过此部分.

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.

这篇关于如何使用&lt; ui:repeat&gt;遍历嵌套列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 02:05