Limit the number of iterations in ui: repeat

We have a JSF page that displays a table with query results. We want to show only the 3 best results.

How to do this with <ui:repeat>?

We cannot do this in the business layer because it is not under our control. We need to limit the results to 3 in the field of view.

+4
source share
2 answers

You can follow how kocko suggests in his answer, but of course, it is quite difficult to iterate over the whole list to output only three components.

, size <ui:repeat> - EL , , 3. . Jsf ui: java bean.

, 3 , size:

<ui:repeat var="var" value="#{bean.list}" size="3">
    <h:outputText value="#{var}" />
</ui:repeat>

, EL2.2 +, , List#subList(from, to):

<ui:repeat var="var" value="#{bean.list.subList(0, (bean.list.size() gt 3) ? 3 : bean.list.size())}">
    <h:outputText value="#{var}" />
</ui:repeat>
+8

:

  • <ui:param>, . 3.
  • <ui:repeat> varStatus index, .

:

<ui:param name="limit" value="3"/>
<ui:repeat var="item" value="#{managedBean.list}" varStatus="status">
    <ui:fragment rendered="#{status.index lt limit}">
        <! -- place your value-holding-component here -->
    </ui:fragment>
</ui:repeat>

, 3 , <ui:repeat>.

, rendered <ui:fragment> JSF 2.1. JSF 2.1, <ui:fragment>

<h:panelGroup rendered="#{status.index lt limit}">
    <! -- place your value-holding-component here -->
</h:panelGroup>
+2

All Articles