views:

746

answers:

1

I have the following piece of code in my jsp :

<% pageContext.setAttribute("warnings",Globals.WARNING_MESSAGES); %>
<c:choose>
    <c:when test="${requestScope[pageScope.warnings] or sessionScope[pageScope.warnings]}">
     <html:errors header="warnings.header" footer="warnings.footer" prefix="warnings.prefix" suffix="warnings.suffix"/>
     <c:remove var="${pageScope.warnings}" scope="session"/>
    </c:when>
    <c:otherwise>
     <html:errors/>
    </c:otherwise>
</c:choose>

I wonder if there is anyway (without delving into the source code) to know if an attribute is available for EL coding.

In this code I would like to use a scripting variable define as a constant that I set in the pageScope container. I would like to use the same mechanism when I remove the variable from the sessionScope referencing the scripting variable but it seems that the <c:remove var> attribute refuses to interpret my scripting variable and this ruins all the effort make to reference my Constant declaration. I can use a jsp scriptlet to work around this but is there any "better" way of doing this ?

+1  A: 

I'm not sure I understand your question, but I think you're looking for the "empty" operator for EL to test if an attribute exists:

<c:if test="${empty pageScope.warnings}">
//do something
</c:if>

This will return true if pageScope.warnings is not defined (null).

Eric Wendelin