Search code examples
jstl

JSTL "c:choose" and "c:set" error


I have a problem with JSTL view, here the code part with problem :

<c:set var="tabligne" value="2"></c:set>
<c:choose>
    <c:when test="${tabligne == 1 }"></c:when>
        <c:set var="tabligne" value="${tabligne+1 }"></c:set>
    <c:otherwise>
        <c:set var="tabligne" value="${tabligne-1 }"></c:set>
    </c:otherwise>
</c:choose>

The error message is :

Illegal child tag in "c:choose" tag: "c:set" tag

Solution

  • Probably you want something like this:

      <c:choose>
            <c:when test="${tabligne == 1 }">
                <c:set var="tabligne" value="${tabligne+1 }"></c:set>
            </c:when>
            <c:otherwise>
                <c:set var="tabligne" value="${tabligne-1 }"></c:set>
            </c:otherwise>
        </c:choose>
    

    In your code, the c:set is being detected as c:choose child, and that is wrong.