Arun R
Arun R

Reputation: 8392

Ternary Operator in JSP EL fails

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"}/>           

Upvotes: 3

Views: 8520

Answers (2)

BalusC
BalusC

Reputation: 1108852

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}" />           

Upvotes: 3

Dead Programmer
Dead Programmer

Reputation: 12575

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 } "/>     

Upvotes: 0

Related Questions