Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is better? [closed]

Tags:

jsp

jstl

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>
like image 294
user624558 Avatar asked Jun 18 '12 20:06

user624558


3 Answers

Neither, this looks best for me:

<c:set var="var1" value="${someCondition}" scope="request"/>
like image 65
Tomasz Nurkiewicz Avatar answered Oct 18 '22 20:10

Tomasz Nurkiewicz


The first, because it is more concise.

like image 36
Ned Batchelder Avatar answered Oct 18 '22 20:10

Ned Batchelder


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"/>
like image 20
alextiley Avatar answered Oct 18 '22 18:10

alextiley