Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Don't understand JspTagException: "Illegal use of <when>-style tag without <choose> as its direct parent

I've been staring at the tag nesting below for about an hour now and I still can't figure out why I keep getting a JspTagException:

"Illegal use of <when>-style tag without <choose> as its direct parent"

Are you not allowed to nest condition tags this deeply in JSTL?

<c:choose>
    <c:when test="${rec.image1Available}">
    <img alt="altname" src="/img1.jpg" alt="altname" />
    <c:otherwise>
    <c:choose>
        <c:when test="${rec.image2Available}">
        <img alt="altname" src="/img2.jpg" alt="altname" />
            <c:otherwise>
            <c:choose>
                <c:when test="${rec.image3Available}">
                <img alt="altname" src="img3.jpg" alt="altname" />
                    <c:otherwise>
                    <img alt="altname" src="/holder.jpg" alt="altname" />
                    </c:otherwise>
                </c:when>
            </c:choose>
            </c:otherwise>
        </c:when>
    </c:choose>
    </c:otherwise>
    </c:when>
</c:choose>
like image 484
Egg Yolk Avatar asked Sep 06 '10 15:09

Egg Yolk


2 Answers

You have <c:otherwise> inside <c:when>. <c:otherwise> should be used as follows:

<c:choose>
    <c:when ... >
        1st alternative
    </c:when>
    <c:when ... >
        2nd alternative
    </c:when>
    ...
    <c:otherwise>
        otherwise
    </c:otherwise>
</c:choose>
like image 88
axtavt Avatar answered Nov 15 '22 13:11

axtavt


You have <c:otherwise> tags nested inside <c:when> tags. These 2 tags need to be peer to each other. Try this:

<c:choose>
    <c:when test="${rec.image1Available}">
        <img src="/img1.jpg" alt="altname" />
    </c:when>
    <c:otherwise>
        <c:choose>
            <c:when test="${rec.image2Available}">
                 <img src="/img2.jpg" alt="altname" />
            </c:when>
            <c:otherwise>
                <c:choose>
                    <c:when test="${rec.image3Available}">
                        <img src="img3.jpg" alt="altname" />
                    </c:when>
                    <c:otherwise>
                        <img src="/holder.jpg" alt="altname" />
                    </c:otherwise>
                </c:choose>
            </c:otherwise>
        </c:choose>
    </c:otherwise>
</c:choose>

BTW: You have alt attributes listed twice in each of your <img> tags. I removed the extra ones in my answer.

like image 24
Asaph Avatar answered Nov 15 '22 14:11

Asaph