Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concat two String in JSF EL expression [duplicate]

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?

like image 888
Tapas Bose Avatar asked Jun 14 '13 06:06

Tapas Bose


People also ask

How do you concatenate 2 strings?

You concatenate strings by using the + operator. For string literals and string constants, concatenation occurs at compile time; no run-time concatenation occurs. For string variables, concatenation occurs only at run time.

Can you use a double in string concatenation?

The “+” operator with a String acts as a concatenation operator. Whenever you add a String value to a double using the “+” operator, both values are concatenated resulting a String object. In-fact adding a double value to String is the easiest way to convert a double value to Strings.

Which function is used to concat the two strings?

Use CONCATENATE, one of the text functions, to join two or more text strings into one string. Important: In Excel 2016, Excel Mobile, and Excel for the web, this function has been replaced with the CONCAT function.

What is return type of concat () method?

Java - String concat() Method The method returns a String with the value of the String passed into the method, appended to the end of the String, used to invoke this method.


1 Answers

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'}"/>

like image 199
Marcio Aguiar Avatar answered Oct 04 '22 17:10

Marcio Aguiar