mabi
mabi

Reputation: 5306

How do I iterate over a sublist with ui:repeat?

I'm migrating a piece of legacy code that looks like this:

<c:forEach items="#{sel}" var="crit" end="12">
  <tr>
    <td class="criteriaName">
      <c:set var="tip" value="#{Factory.makeTooltip(crit.string)}" />

      <c:if test="#{0 != fn:length(tip)}">
        <a:outputPanel layout="block">
          <h:outputText value="#{crit.kriterium}" styleClass="tooltipAvailable"/>
            <rich:tooltip layout="block">
              <h:outputText escape="false" value="#{tip}" />
            </rich:tooltip>
         </a:outputPanel>
       </c:if>

       <c:if test="#{0 == fn:length(tip)}">
         <h:outputText value="#{crit.kriterium}" />
       </c:if>
     </td>
  </tr>
</c:forEach>

Now I'm looking to replace <c:if> and <c:forEach> with their <ui:fragment> and <ui:repeat> counterparts. Problem is, I need to iterate over sel twice: once from 0 to 12 and then from 13 to the end.

I haven't found a way to split the list iteration the way the end attribute of the foreach tag does it. I'd really like to avoid splitting the list in the backend as this is a pure view issue and should be handled there.

So the question is: can i replace the above fragment the way I specified? What are the alternatives?

Upvotes: 1

Views: 974

Answers (1)

Joeri Hendrickx
Joeri Hendrickx

Reputation: 17445

If you're using EL 2.2, you can invoke normal java methods.

Assuming that sel is a List here, you can use

<ui:repeat var="crit" value="#{sel.subList(0,12)}">

Not that ui:repeat and c:forEach are not always interchangeable, so make sure your use case is valid.

Upvotes: 5

Related Questions