不能使用“结束" JSF 2.0重复标签的varStatus的属性 [英] can't use the "end" property of JSF 2.0 repeat tag's varStatus

查看:161
本文介绍了不能使用“结束" JSF 2.0重复标签的varStatus的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JSF 2.0的repeat标记遍历对象列表并显示其某些属性.我想使用repeatvarStatus属性,以便可以访问循环索引,最后一个列表项的编号,并判断是否已到达列表的末尾(因此不会出现间隔符)显示).我认为这会起作用:

I'm using the repeat tag of JSF 2.0 to loop through a list of objects and display some of their properties. I want to use the varStatus attribute of repeat so that I can access the loop index, the number of the last list item, and to tell whether the end of the list has been reached (so the spacer won't be displayed). I thought this would work:

<ui:repeat var="anObject" varStatus="repeatStatus" value="#{objectList}">
    <h:panelGroup>
        <h:outputText value="Item #{repeatStatus.index + 1} of #{repeatStatus.end}" />
        <h:outputText value="#{anObject.text}" />
    </h:panelGroup>

    <h:outputText value="&nbsp;" rendered="#{false == repeatStatus.last}" />
</ui:repeat>

但是,它从不显示repeatStatus.end的任何内容. indexlast属性运行良好.

However, it never displays anything for repeatStatus.end. The index and last properties work well.

我尝试使用objectList.size(),而不是repeatStatus.end,但这仅适用于列表中的第一项.

Instead of repeatStatus.end, I tried using objectList.size(), but that worked for only the first item in the list.

如何在"y的x项"文本中显示列表中的项数?

How can I display the number of items in the list as part of the "Item x of y" text?

推荐答案

仅在设置size属性时使用end.

<ui:repeat ... size="#{fn:length(objectList)}">

或者,您也可以直接使用它.

Alternatively, you can also just use it directly.

Item #{repeatStatus.index + 1} of #{fn:length(objectList)}

顺便说一句,#{false == repeatStatus.last}中的布尔比较是丑陋的.它已经返回了一个布尔值;如果要取消它,请使用#{not repeatStatus.last}.

By the way, the boolean comparison in #{false == repeatStatus.last} is ugly. It returns a boolean already; if you want to negate it, rather use #{not repeatStatus.last}.

这篇关于不能使用“结束" JSF 2.0重复标签的varStatus的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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