I know this is an old topic, but the answer to this question has changed in the past six months, and it's important to note that change, IMO (since I found this by Googling "el concatenate strings").
As of EL Expression 3.0 (public ballot approved August 2012, released with Java EE 7), a twist on the syntax the questioner originally used is now valid:
${var1 == 0 ? 'hi' : 'hello ' += var2}
There was much disagreement with the use of +=
instead of +
, but it is what it is. This will correctly evaluate and concatenate the strings as expected. You can also use the cat
operator instead of the +=
operator:
${var1 == 0 ? 'hi' : 'hello ' cat var2}
While this is now legal, note that you won't be able to use it until your web container (Tomcat, Jetty, GlassFish, etc.) releases a new version that supports Java EE 7/EL 3.0. This is expected sometime before the end of 2013, perhaps as early as the fall.
Edited 2015-02-19 to note that the final operator was +=
and not +
as originally answered.