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 1,836 times, 1 visits today)

Leave a Comment