【问题标题】:How to properly use <ui:repeat> [duplicate]如何正确使用 <ui:repeat> [重复]
【发布时间】:2018-10-19 14:48:01
【问题描述】:

我在 JSF 页面中使用 &lt;ui:repeat&gt; 时遇到问题。我有一个 arrayList 传递给它,但是,它从不迭代显示内容。

我知道有内容,因为当我使用&lt;h:datatable&gt; 执行完全相同的操作时,它会显示内容。因此,如果有人可以向我解释为什么使用 &lt;ui:repeat&gt; 不起作用但使用 &lt;h:datatable&gt; 不起作用,那就太好了。

这里是&lt;h:datatable&gt; 代码:

<h:dataTable value="#{proposalAction.proposal.proposalCountries}" var="pc" rendered="#{proposalAction.proposal.proposalCountries !=null and proposalAction.proposal.proposalCountries.size() > 0}">
    <h:column>
        <img src="/resources/images/flags/#{utils.getValidCountryFlagDisplayCode(pc.country)}.png" title="#{pc.country.getDisplayName(localeSelector.locale)}" alt="#{pc.country.getDisplayName(localeSelector.locale)}" width="20" />      
        &#160;
        <h:outputText value="#{pc.country.getDisplayName(localeSelector.locale)}" />
    </h:column>
</h:dataTable>

这是使用&lt;ui:repeat&gt;代码的代码:

<ul>
    <ui:repeat items="#{proposalAction.proposal.proposalCountries}" var="pc" rendered="#{proposalAction.proposal.proposalCountries !=null and proposalAction.proposal.proposalCountries.size() > 0}">
        <li>
            <img src="/resources/images/flags/#{utils.getValidCountryFlagDisplayCode(pc.country)}.png" title="#{pc.country.getDisplayName(localeSelector.locale)}" alt="#{pc.country.getDisplayName(localeSelector.locale)}" width="20" />      
            &#160;<h:outputText value="#{pc.country.getDisplayName(localeSelector.locale)}" />
        </li>
    </ui:repeat>
</ul>

如您所见,它们是相同的。数据表显示国家/地区,但转发器在&lt;ul&gt; 内没有显示任何内容……我不知所措……请帮忙!

【问题讨论】:

    标签: jsf facelets uirepeat


    【解决方案1】:

    如果您有适当的 getter 和 setter,请尝试使用 #{pc.country.displayName} 作为您的 h:outputText 标记的值。 ui:repeat 没有items 属性,因此请改用value。我假设displayName 是您主列表中Country 的属性。您可以在 getter 中编写特定的 Locale 逻辑。

    这应该可行:

    <ul>
        <ui:repeat value="#{proposalAction.proposal.proposalCountries}" var="pc" rendered="#{proposalAction.proposal.proposalCountries !=null and proposalAction.proposal.proposalCountries.size() > 0}">
            <li>
                <h:outputText value="#{pc.country.displayName}" />
            </li>
        </ui:repeat>
    </ul>
    

    也对您的img 标签进行此类调整。 您还应该将 rendered 的逻辑放在后端 bean 中,并在 UI 上使用单个布尔值。如redered="#{displayCountries}

    【讨论】:

    • ;-) 如此有效的'rtfm'
    猜你喜欢
    • 1970-01-01
    • 2020-03-21
    • 1970-01-01
    • 2018-03-01
    • 2017-11-16
    • 1970-01-01
    • 1970-01-01
    • 2011-04-02
    • 2019-07-28
    相关资源
    最近更新 更多