views:

171

answers:

2

We're using JBoss 4.22 with portlets. When the listener tag is not in the web.xml the portlet loads, but the listener sessionDestroyed() is never called (obviously). When added the portlet isn't loaded, and there aren't any exceptions or log messages. Are there any gotchas I should be aware of?

   <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
             version="2.4">


           <!-- Listeners used by application -->
        <listener>
         <listener-class>listenerpackage.MyClassThatImplementsHttpSessionListener</listener-class>
        </listener>
    ...Other tags...
    </web-app>

In reply to the comments I have been looking through the code to find trouble spots. My Listener's constructor does have some possible trouble. Normally (not as listener) an instance would be made by the relevant portlet's (the one that isn't loaded when the listener is added to the web.xml) constructor. Can I still expect this to be the case or does the container create a instance itself?

+1  A: 

The problem is that listeners declared in the deployment document are instantiated when that document is loaded. My class was designed to be instantiated by the portlet so needed info wasn't available.

A solution is to use an HttpSession**Binding**Listener and adding the class as an attribute to the session. Then the unbound() is called when the session invalidates. :)

Adam
A: 

Is your listener node in the right order in your web.xml? Maybe it's being ignored due to not following the DTD? For instance, servlets, servlet-mappings, session-configs are all supposed to be before the listener.

Greg
Where did you see this? My searches tended to show the listener tag at both the top and bottom. I've also read some threads stating that it only matters for repeats and parameters, though I don't have them now.
Adam