--Environment - CentOS Linux release 7.8.2003 (Core) - openjdk version "11.0.7" 2020-04-14 LTS - JSF 2.3.9
Reference: Several ways to concatenate strings separated by commas in Java --Qiita
xhtml
<!--abridgement-->
<h5>Output a list of strings as comma-separated strings</h5>
<h:outputText value="#{sampleBean.commaDelimitedString}" />
<!--abridgement-->
SampleBean.java
//abridgement
/**List of strings. */
@Getter
private List<String> strings = Arrays.asList("Of the string", "List", "Separated by commas", "I want to display it.");
/**
*Get a list of strings as comma separated strings.
* @return Comma-separated string
*/
public String getCommaDelimitedString() {
return this.strings.stream().collect(Collectors.joining(","));
}
//abridgement
xhtml
<!--abridgement-->
<ui:repeat var="string" value="#{sampleBean.strings}" varStatus="index">
<h:outputText value="#{string}" />
<ui:fragment rendered="#{!index.last}">,</ui:fragment>
</ui:repeat>
<!--abridgement-->
SampleBean.java
//abridgement
/**List of strings. */
@Getter
private List<String> strings = Arrays.asList("Of the string", "List", "Separated by commas", "I want to display it.");
//abridgement
Recommended Posts