What's better?

which of the following is better?

<c:set var="var1" value="false" scope="request"/>
<c:if test="${someCondition}">
    <c:set var="var1" value="true" scope="request"/>
</c:if>

Or the following

<c:choose>
    <c:when test="${someCondition}">
        <c:set var="var1" value="true" scope="request"/>
    </c:when>
    <c:otherwise>
        <c:set var="var1" value="false" scope="request"/>
    <c:otherwise>
</c:choose>
+5
source share
3 answers

For me it does not look better:

<c:set var="var1" value="${someCondition}" scope="request"/>
+5
source

First, because it is more concise.

+2
source

I would do what Tomas suggested. If you have different values, not logical ones, you can use a three-dimensional statement:

<c:set var="var1" value="${someCondition == 'someValue' ? 'valueA' : 'valueB'}" scope="request"/>
+1
source

All Articles