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?
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.
There are two ways to concatenate strings in Java: By + (String concatenation) operator. By concat() method.
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.
With EL 2 you can do the following:
#{'this'.concat(' is').concat(' a').concat(' test!')}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With