tags:

views:

33

answers:

2

Is nesting of EL Expressions in Ternary Operator allowed?

What is wrong with the following expression?

<input class="text_field" type="text" name="receivedBy" id="receivedBy" style="width:250px;"  maxlength="64" value="${empty obj.val ? obj1.attr1.val ' ' obj2.attr1.val: obj3.val"}/>           
A: 

just try with the below one

<input class="text_field" type="text" name="receivedBy" id="receivedBy" style="width:250px;"  maxlength="64" value="${empty obj.val ? obj1.attr1.val ' ' obj2.attr1.val: obj3.val } "/>     
Suresh S
Thanks, but the brace is closed in code. Issue is not about the brace.
Icarus
@icarus what is the single empty quotes between obj1.attr1.val and obj2.attr1.val
Suresh S
@Suresh That was supposed to be a white space. But removing that also still maintains the problem.
Icarus
+1  A: 

You are actually not nesting EL expressions (nesting would look like ${foo${bar}baz} which is actually not possible). You are attempting to concat EL outcomes as a String. You cannot concat Strings in EL that way. Your best bet is to use c:set to preset it.

<c:set var="obj1obj2val" value="${obj1.attr1.val} ${obj2.attr1.val}" />
<input value="${empty obj.val ? obj1obj2val : obj3.val}" />           
BalusC
This is the approach I took finally. Apparently, the obj1 did not exist.
Icarus