views:

45

answers:

2

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>
+3  A: 

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>
axtavt
+4  A: 

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.

Asaph