Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String Concatenation in EL [duplicate]

I would like to concatenate a string within a ternary operator in EL(Expression Language).

Suppose there is a variable named value. If it's empty, I want to use some default text. Otherwise, I need to append it with some static text.

${(empty value)? "none" : value + " enabled"} 

This will not compile however. What would be a correct way to write this? Or is this even possible?

like image 252
Tom Tucker Avatar asked Sep 03 '10 23:09

Tom Tucker


People also ask

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.

What are the 2 methods used for string concatenation?

There are two ways to concatenate strings in Java: By + (String concatenation) operator. By concat() method.

Which is an example of string concatenation?

In formal language theory and computer programming, string concatenation is the operation of joining character strings end-to-end. For example, the concatenation of "snow" and "ball" is "snowball". In certain formalisations of concatenation theory, also called string theory, string concatenation is a primitive notion.


1 Answers

With EL 2 you can do the following:

#{'this'.concat(' is').concat(' a').concat(' test!')} 
like image 107
Joel Avatar answered Sep 28 '22 05:09

Joel