How to check enum values ​​in JSTL EL test?

I have the following block in my JSP that converts ENUM values {CREATE, CREATE_FROM_CAMPAIGN, OPEN}to good, readable status texts.

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

<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 of the following results:

was opened (CREATE_FROM_CAMPAIGN)

was open (OPEN)

Why doesn't the second test work?

+5
source share
1 answer

This does not work because you used $(instead ${to run the expression.

Correct 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>
+9
source

All Articles