Concat two String in JSF EL expression

Tapas Bose picture Tapas Bose · Jun 14, 2013 · Viewed 86.8k times · Source

I have the following el expression:

<af:outputText value="#{viewArticle.publish ? ('Publish on ' + viewArticle.publishDate + ' by ' + viewArticle.publishFirstName + ' ' + viewArticle.publishLastName) : 'Draft version'}"/>

But I am getting

java.lang.NumberFormatException: For input string: "Publish on "

How can I join the string?

Answer

Marcio Aguiar picture Marcio Aguiar · Nov 4, 2013

You can use the String.concat function:

<af:outputText value="#{viewArticle.publish ? 'Publish on '.concat(viewArticle.publishDate).concat(' by ').concat(viewArticle.publishFirstName).concat(' ').concat(viewArticle.publishLastName) : 'Draft version'}"/>