which one 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>
Neither, this looks best for me:
<c:set var="var1" value="${someCondition}" scope="request"/>
The first, because it is more concise.
I'd do what Tomasz suggested. If you have different values rather than booleans, you can use a ternary statement:
<c:set var="var1" value="${someCondition == 'someValue' ? 'valueA' : 'valueB'}" scope="request"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With