jstl: using session parameter in test

J

John Pedersen

Hi,

I have:

<jsp:useBean id="messageHandler"
type="com.starfriend.messages.MessageHandler" scope="application" />

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>

<c:choose>
<c:when test="${messageHandler.hasUnreadMessage(session.userName)}">
<img src="../images/newmail.gif" width="145" height="11">
</c:when>
<c:eek:therwise>
No new Messages.
</c:eek:therwise>
</c:choose>

I think you should be able see what I am trying to do - but

messageHandler.hasUnreadMessage(session.userName)

isn't the right syntax. How can I get the userName, which has
previously been added to the session, and use that as a parameter for
the method hasUnreadMessage()?

I have looked all over for an example of this - can anyone show me the
correct syntax (it must be possible...?)

Thanks in advance,

John Pedersen
 
T

Tobias Schierge

John said:
<c:when test="${messageHandler.hasUnreadMessage(session.userName)}">

This is not possible, a solution for this is would be:

<c:when test="${not empty messageHandler.unreadMessage[userName]}">

In order to use this you need to implement

public Hashtable getUnreadMessage()
{
....
}

in your class to have a bean-call compatible method.

Regards,

Tobias
 
J

John Pedersen

In my class MessageHandler, I have this method:

public boolean isUnreadMessage(String userName)

When I try:

<c:when test="${messageHandler.unreadMessage[userName]}">

I get this error message:

javax.servlet.jsp.JspTagException: javax.servlet.jsp.JspException: An
error occurred while evaluating custom action attribute "test" with
value "${messageHandler.unreadMessage[userName]}": Unable to find a
value for "tash" in object of class "java.lang.Boolean" using operator
"[]" (null)

"tash" is the value of the userName in that session.

Isn't isUnreadMessage(String userName) a bean-call compatible method?

Thanks,

John

Tobias Schierge said:
John said:
<c:when test="${messageHandler.hasUnreadMessage(session.userName)}">

This is not possible, a solution for this is would be:

<c:when test="${not empty messageHandler.unreadMessage[userName]}">

In order to use this you need to implement

public Hashtable getUnreadMessage()
{
....
}

in your class to have a bean-call compatible method.

Regards,

Tobias
 
T

Tobias Schierge

John said:
Isn't isUnreadMessage(String userName) a bean-call compatible method?

It isnt, i'm afraid..bean-getters have no parameter.

The only way to use a parameter in your situation is a getter method that
returns something that implements Map-interface.

As i already wrote you need to use:

public Map getUnreadMessage()
{
...
}

and then

<c:if value="${empty handler.unreadMessage[userName]}">

or something like this.

Regards,

Tobias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,201
Latest member
KourtneyBe

Latest Threads

Top