如何使用<ui:repeat>迭代嵌套列表? [英] How to use <ui:repeat> to iterate over a nested list?

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

问题描述

使用 JSF 2.0,我需要显示一个表格,其中每一行都包含一个打开弹出窗口的链接.我有两个模型: AidList 属性和 Bidname 属性.在我的支持 bean 中,我有一个 List 属性.在我看来,我使用 来迭代 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>.

要求是,根据用户点击的行,需要显示A对应的List.但是, 不接受要在 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.

我如何有效地解决这个问题?

How do I efficiently solve this problem?

推荐答案

你需要的是在你的外层迭代中嵌套另一个 标签:

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 监听器未在嵌套 ui:repeat 中调用 以及许多不那么近的问题以及他们的回答),这可能会导致未调用动作侦听器等,但如果您目前正在使用最新的 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;迭代嵌套列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆