Search code examples
jsfuirepeat

JSF ui:repeat | Just display the first 5 elements of a List


Hi can someone tell me if its possible to just render the first 5 elements of a list with ui:repeat without creating a seperate List for this?

I googled but couldn't find something about this.

Thank you for your answers in advance.


Solution

  • You can simply use the end attribute for that. From the documentation:

    If value specified: Iteration ends at the item located at the specified index (inclusive). If value not specified: Iteration ends when index reaches the specified value (inclusive).

    Note that there also is a begin attribute. Documentation:

    If value specified: Iteration begins at the item located at the specified index. First item of the collection has index 0. If value not specified: Iteration begins with index set at the specified value.

    So you can simply do:

    <ui:repeat value="#{myBean.myCollection}" end="4" ...>
      ...
    </ui:repeat>