tags:

views:

73

answers:

3

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?

+1  A: 

The + operator has not the same effect on Strings in EL as in Java. Best what you can do is to preset it using <c:set>.

<c:set var="enabled" value="${value} enabled" />
<c:out value="${empty value ? 'none' : enabled}" />
BalusC
+4  A: 

There is no string concatenation operator in EL. If you don't need the concatenated string to pass into some other operation, just put these expressions next to each other:

${value}${(empty value)? 'none' : ' enabled'}
McDowell
Oh, that is also a way :)
BalusC
A: 

1.The +(operator) has not effect to that in using EL. 2.so this is the way,to use that

is this helpful to You ?

AdalArasan
@AdalArasan - indent four spaces for code blocks and use the backtick character to escape angle-brackets. http://stackoverflow.com/editing-help
McDowell