开发者

How to test against enum values in JSTL EL test?

开发者 https://www.devze.com 2023-04-01 14:50 出处:网络
I have the following block in my JSP, which converts from ENUM values {CREATE, CREATE_FROM_CAMPAIGN, OPEN} into nice, readable status texts.

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'}">
        &l开发者_开发问答t;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?


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消