tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lieven De Keyzer" <>
Subject RE: c:choose not evaluating correctly
Date Mon, 30 May 2005 22:32:21 GMT
Try using

<c:when test="${null == sessionScope.userSession}">

>From: "Andy" <>
>Reply-To: "Tag Libraries Users List" <>
>To: <>
>Subject: c:choose not evaluating correctly
>Date: Mon, 30 May 2005 20:31:52 +0100
>Hi All,
>I have a menu in which I want to display a 'login' link when an object
>called 'userSession' does not exist in the session scope, and a 'logout'
>link when the 'userSession' object does exist in the seesion scope.
>I'm using Struts, and the 'userSession' object is set in an 
>method when a form is submitted containing a valid username and password
>i.e. -
>         UserSession s = new UserSession();
>         s.setUsername(username);
>         // Save the user session object
>         request.getSession().setAttribute("userSession",s);
>So I figure this is all I have to do is -
>     <c:choose>
>         <c:when test="${empty sessionScope.userSession}">
>             <html:link action="/login"><bean:message
>         </c:when>
>         <c:otherwise>
>             <html:link action="/logout"><bean:message
>         </c:otherwise>
>     </c:choose>
>However in the test case where I have not logged in, so the action that 
>the userSession object is not invoked, this doesn't work as expected. The
>else part is always evaluated, indicating that sessionScope.userSession
>isn't empty when I know it is! If I print out an attribute of the
>userSession object -
><jsp:getProperty name="userSession" property="username"></jsp:getProperty>
>I get 'null' displayed - this is correct because the userSession object
>doesn't exist, but the c:choose doesn't evaluate correctly.
>Clearly I'm doing something wrong, but I just can't see what it is, or even
>if it's a JSTL issue.
>To unsubscribe, e-mail:
>For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message