How to test against enum values in JSTL EL test?
Asked Answered
A

1

5

I have the following block in my JSP, which converts from ENUM values {CREATE, CREATE_FROM_CAMPAIGN, OPEN} into nice, readable status texts.

For some reason the first test against 'CREATE' works, but the test against the 'CREATE_FROM_CAMPAIGN' does not.

<c:choose>
    <c:when test="${entry.activity eq 'CREATE'}">
        <td>was created</td>
    </c:when>
    <c:when test="$(entry.activity eq 'CREATE_FROM_CAMPAIGN'}">
        <td>was created from campaign</td>
    </c:when>
    <c:otherwise>
        <td>was opened (${entry.activity}) </td>
    </c:otherwise>
</c:choose>

One output from this one is as follows:

was opened (CREATE_FROM_CAMPAIGN)

was opened (OPEN)

Why does the second test not work?

Aver answered 29/8, 2011 at 13:17 Comment(0)
T
9

It does not work because you used $( instead of ${ to start the expression.

Fix it accordingly:

<c:choose>
    <c:when test="${entry.activity eq 'CREATE'}">
        <td>was created</td>
    </c:when>
    <c:when test="${entry.activity eq 'CREATE_FROM_CAMPAIGN'}">
        <td>was created from campaign</td>
    </c:when>
    <c:otherwise>
        <td>was opened (${entry.activity}) </td>
    </c:otherwise>
</c:choose>
Ty answered 29/8, 2011 at 13:21 Comment(1)
Thank you. Just could not spot that curly bracket despite looking over that code for a long while. I've flagged my post for attention, though, because it does not benefit anyone else.Aver

© 2022 - 2024 — McMap. All rights reserved.