can't use the “end” property of JSF 2.0 repeat tag's varStatus

左心房为你撑大大i 提交于 2019-12-19 11:57:17

问题


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>

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

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

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


回答1:


The end is only used when you set the size attribute.

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

Alternatively, you can also just use it directly.

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

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



来源:https://stackoverflow.com/questions/11766259/cant-use-the-end-property-of-jsf-2-0-repeat-tags-varstatus

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!