tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andy" <a...@fritter.net>
Subject RE: c:choose not evaluating correctly
Date Tue, 31 May 2005 10:50:13 GMT

Hi Martin,

That evaluates to false all the time. When userSession does not exist, and
when it does exist and username is not empty.

Is it necessary to use sessionScope.mybean.myproperty syntax ?

I'm beginning to think this must be some other problem. None of the below
variations evaluate to true when userSession does not exist (neither do they
evaluate to true when it does exists, but that's expected of course).

    <c:if test="${empty userSession.username}">if empty</c:if>
    <c:if test="${empty sessionScope.userSession.username}">if empty</c:if>
    <c:if test="${empty sessionScope.userSession}">if empty</c:if>
    <c:if test="${null == userSession.username}">if empty</c:if>
    <c:if test="${null == sessionScope.userSession.username}">if
empty</c:if>
    <c:if test="${null == sessionScope.userSession}">if empty</c:if>

I'm using Tomcat with Struts, perhaps the problem is with them.

Andy.


>-----Original Message-----
>From: Gros, Martin [mailto:gros_martin@emc.com]
>Sent: 31 May 2005 10:46
>To: Tag Libraries Users List
>Subject: RE: c:choose not evaluating correctly
>
>
>Try
>
>    <c:choose>
>        <c:when test="${userSession.username}">
>            <html:link action="/logout"><bean:message
>key="main.menu.logout"/>
>		</html:link>
>        </c:when>
>        <c:otherwise>
>            <html:link action="/login"><bean:message
>key="main.menu.login"/>
>		</html:link>
>        </c:otherwise>
>    </c:choose>
>
>-----Original Message-----
>From: Andy [mailto:andy@fritter.net]
>Sent: Dienstag, 31. Mai 2005 11:37
>To: Tag Libraries Users List
>Subject: RE: c:choose not evaluating correctly
>
>
>Thanks, but I still get the same result, it's as if the 'test'
>function just
>refuses to work. Here's the test page I'm using -
>
><%@ page contentType="text/html;charset=UTF-8" language="java" %>
><%@ taglib
>uri="/tags/struts-bean" prefix="bean" %> <%@ taglib uri="/tags/struts-html"
>prefix="html" %> <%@ taglib uri="/tags/struts-logic" prefix="logic" %> <%@
>taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
>
><html>
><head>
>    <link rel="stylesheet" type="text/css"
>          href="<html:rewrite page="base.css" />" />
>    <title><bean:message key="welcome.title"/></title> </head>
>
>Username:
><jsp:useBean id="userSession" scope="session"
>class="template.filter.UserSession"/>
><jsp:getProperty name="userSession" property="username"></jsp:getProperty>
>
><table>
><tr>
>    <td>
>    <c:choose>
>        <c:when test="${null == userSession.username}">
>            <html:link action="/login"><bean:message
>key="main.menu.login"/>
>		</html:link>
>        </c:when>
>        <c:otherwise>
>            <html:link action="/logout"><bean:message
>key="main.menu.logout"/>
>		</html:link>
>        </c:otherwise>
>    </c:choose>
>    </td>
></tr>
></table>
></body>
></html>
>
>>-----Original Message-----
>>From: Lieven De Keyzer [mailto:lieven_dekeyzer@hotmail.com]
>>Sent: 30 May 2005 23:32
>>To: taglibs-user@jakarta.apache.org
>>Subject: RE: c:choose not evaluating correctly
>>
>>
>>Try using
>>
>><c:when test="${null == sessionScope.userSession}">
>>
>>>From: "Andy" <andy@fritter.net>
>>>Reply-To: "Tag Libraries Users List" <taglibs-user@jakarta.apache.org>
>>>To: <taglibs-user@jakarta.apache.org>
>>>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
>>>Action.execute()
>>>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
>>>key="main.menu.login"/></html:link>
>>>         </c:when>
>>>         <c:otherwise>
>>>             <html:link action="/logout"><bean:message
>>>key="main.menu.logout"/></html:link>
>>>         </c:otherwise>
>>>     </c:choose>
>>>
>>>However in the test case where I have not logged in, so the action
>>>that sets 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.
>>>
>>>Thanks,
>>>
>>>Andy.
>>>
>>>
>>>
>>>
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
>>>For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>>>
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>>
>>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Mime
View raw message