迭代h中的嵌套列表属性:datatable [英] Iterate over nested List property inside h:datatable

查看:130
本文介绍了迭代h中的嵌套列表属性:datatable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    <h:dataTable value="#{SearchingBeans.list}" var="entry">
        <h:column>
            <f:facet name="header">
                <h:outputLabel>Photo</h:outputLabel>
            </f:facet>
        </h:column>
        <h:column>
            <f:facet name="header">
                <h:outputLabel>Pseudo</h:outputLabel>
            </f:facet>
            <h:outputLabel value="#{entry.pseudo}"></h:outputLabel>
        </h:column>
        <h:column>
            <f:facet name="header">
                <h:outputLabel>Description</h:outputLabel>
            </f:facet>
            <h:outputLabel value="#{entry.description}"></h:outputLabel>
        </h:column>
        <h:column>
            <f:facet name="header">
                <h:outputLabel>Photo</h:outputLabel>
            </f:facet>
            <h:outputLabel value="#{entry.photo[0].path}"></h:outputLabel> <-- this a List
        </h:column>
    </h:dataTable>

我有一个实体成员他的一个属性是一个列表照片与get / set
该属性是人口
i不知道如何在jsf中获取该值,我只想要为每个成员的第一张图片,因为他们有2-3张照片。可能吗

i got a entities member one of his property is a List photo with get/set that property is populate i don't know how to fetch that value in jsf i want only the first picture for each member since their have 2-3 photos. Its that possible?? any other solution will be appreciate.

推荐答案

只需使用< ui:repeat> < h:dataTable> 通常的方式。将多个迭代组件嵌套在一起是非常有效的。在< h:dataTable> 的情况下,您只需要确保将嵌套的迭代组件放在< h:column>

Just iterate over it using <ui:repeat> or <h:dataTable> the usual way. It's perfectly valid to nest multiple iterating components in each other. In case of <h:dataTable>, you only need to make sure that you put the nested iterating component inside a <h:column>.

例如

<h:dataTable value="#{bean.entities}" var="entity">
    <h:column>
        #{entity.property}
    </h:column>
    <h:column>
        <ui:repeat value="#{entity.subentities}" var="subentity">
            #{subentity.property}
        </ui:repeat>
    </h:column>
</h:dataTable>

<h:dataTable value="#{bean.entities}" var="entity">
    <h:column>
        #{entity.property}
    </h:column>
    <h:column>
        <h:dataTable value="#{entity.subentities}" var="subentity">
            <h:column>
                #{subentity.property}
            </h:column>
        </h:dataTable>
    </h:column>
</h:dataTable>

当您嵌套多个< ui时,您可能会遇到问题:重复> 组件,并在使用旧版Mojarra时使用< f:ajax>

You'll potentially only run into issues when you nest multiple <ui:repeat> components and use <f:ajax> in it while using an older version of Mojarra.

只有JSTL < c:forEach> 在嵌套在JSF迭代组件中时不起作用,因为这里解释的原因 JSF2 Facelets中的JSTL有意义?

Only JSTL <c:forEach> wouldn't work when nested inside a JSF iterating component for the reasons explained here JSTL in JSF2 Facelets... makes sense?

与具体问题无关,请勿滥用< h:outputLabel> 为纯文本演示。它生成一个HTML < label> 元素,该元素意图属性的标签输入元素。但是,您在代码中没有任何地方。您应该使用< h:outputText> 。顺便说一句,我最近在开头的代码中更经常看到这个。必须有一个不好的教程或资源,这是滥用< h:outputLabel> 而不是< h:outputText> 或甚至在模板文本中使用普通EL。你在使用哪个教程/资源?那么我可以联系作者这个严重的误导。另见 h:outputLabel的目的及其for属性

Unrelated to the concrete problem, please don't abuse <h:outputLabel> for pure text presentation. It generates a HTML <label> element which is intented to label an input element by for attribute. However, you're doing that nowhere in the code. You should be using <h:outputText> instead. By the way, I'm lately seeing this more often in code of starters. There must be somewhere a bad tutorial or resource which is abusing the <h:outputLabel> this way instead of <h:outputText> or even plain EL in template text. Which tutorial/resource was you using? Then I can contact the author about this severe misinstruction. See also Purpose of the h:outputLabel and its "for" attribute

这篇关于迭代h中的嵌套列表属性:datatable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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