String Concatenation in EL

Tom Tucker picture Tom Tucker · Sep 4, 2010 · Viewed 101.2k times · Source

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?

Answer

Joel Richard picture Joel Richard · May 11, 2012

With EL 2 you can do the following:

#{'this'.concat(' is').concat(' a').concat(' test!')}