AnsweredAssumed Answered

Gel Script: Passing calculated value into SWITCH statement

Question asked by marlon.mckenzie on Feb 4, 2011
Latest reply on Jan 12, 2016 by JayaSantoshKumar
Hi All,

I am running into a issus when passing a calculated value into a switch statement. For example (as in below code) if I pass in the output2 value, the statement defaults. If I pass either value3 or value4, value="2" case is met and the appropriate output is displayed.

Is there a conversion that must be done on the calculated value before passing it into the switch?

PS: Code snippet below

Regards,
Marlon

Code Snippet:
<core:set var="value1" value="Hello"/>
<core:set var="value2" value="World"/>
<core:set var="output1" value="${value1 + &quot; &quot; + value2}"/>

<core:set var="value3" value="2"/>
<core:set var="value4" value="2"/>
<core:set var="output2" value="${value3 + value4}"/>

<core:switch on="${output2}">
<core:case value="2">
<core:if test="${output1.length() &lt;= '5'}">
<gel:out>"${output1}" contains 5 or less letters and ${output2} = 2}</gel:out>
</core:if>
<core:if test="${output1.length() &gt; '5'}">
<gel:out>"${output1}" contains more than 5 letters and ${output2} = 2}</gel:out>
</core:if>
</core:case>
<core:case value="4">
<core:if test="${output1.length() &lt;= '5'}">
<gel:out>"${output1}" contains 5 or less letters and ${output2} = 4}</gel:out>
</core:if>
<core:if test="${output1.length() &gt; '5'}">
<gel:out>"${output1}" contains more than 5 letters and ${output2} = 4}</gel:out>
</core:if>
</core:case>
<core:default >
<gel:out>${output2} does not meet any of the set conditions. 2/4</gel:out>
</core:default>
</core:switch>

Output:
4 does not meet any of the set conditions. 2/4

Desired Output:
"Hello World" contains more than 5 letters and 4 = 4

Outcomes