How To Output A List As A Comma Separated String In JSF | Example

In a JSF Page you might want to display all entries of a collection as a comma-separated list (or of course another separator). To do that you can use the JSF <ui:repeat></ui:repeat> Tag.


Advertisement

This JSF-Tag expects a collection assigned to the value attribute. <ui:repeat> iterates over the collection and assigns the current item to the variable, which is declared in the var attribute. The variable, assigned in the varStatus attribute has several properties. In the example we need the last property, which indicates witz a boolean value, wheater this is the last item or not.
Here is an example:

<ui:repeat value="#{myCollectionOfStrings}" var="str" varStatus="status">
	#{str}#{status.last?'':', '}
</ui:repeat>

Advertisement
(Visited 2,264 times, 1 visits today)

4 thoughts on “How To Output A List As A Comma Separated String In JSF | Example”

  1. Keep up the wonderful piece of content, I read several
    posts on this site and I think that your web blog is truly appealing as well as includes plenty
    of superb information.

    Reply
  2. I’m not sure exactly why but this website is loading very slow for me.

    Is anyone else having this issue or is it a problem on my
    end? I’ll check back later on and see if the problem still exists.

    Reply

Leave a Comment