I can’t understand how is that possible, so i will just show the code.
This works. As expected, a list of “PAIR” is printed:
<c:forEach var="element" items="${list}">
<c:choose>
<c:when test="true">
<div>PAIR ${element}</div>
</c:when>
<c:otherwise>
<div>ODD ${element}</div>
</c:otherwise>
</c:choose>
</c:forEach>
This doesn’t work. Print only “ODD”:
<c:forEach var="element" items="${list}">
<c:choose>
<c:when test="true == true">
<div>PAIR ${element}</div>
</c:when>
<c:otherwise>
<div>ODD ${element}</div>
</c:otherwise>
</c:choose>
</c:forEach>
Someone can help me?
You are missing the EL literal:
${..}. Usetest="${true == true}"and it will work.The first example works because the string
true, when converted to boolean, istrue. The parser tries to convert the string-value you passed to boolean usingBoolean.valueOf(..). And a conversion of thetrue == truestring, usingBoolean.valueOf(..)gives youfalse.