File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Listener Registration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Listener Registration " Watch "Listener Registration " New topic
Author

Listener Registration

Kamal Tripathi
Ranch Hand

Joined: Oct 02, 2008
Posts: 86
Source: Servlet 2.4 Spec SRV.10.3.3 Listener Registration


The Web container creates an instance of each listener class and registers it for event notifications prior to the processing of the first request by the application. The Web container registers the listener instances according to the interfaces they implement and the order in which they appear in the deployment descriptor. During Web application execution, listeners are invoked in the order of their registration.

In the statement in bold, I understood that listeners are registered in order in which they appear in DD, but what is exactly meant by registration accd to interfaces they implement ??

On the same lines I wanted to ask if in a webapp's DD I configure an HttpSessionAttributeListener and also define a class A implementing HttpSessionBindingListener interface.

Now when objects of class A are set as attributes in session which listener will run first???


Kamal Tripathi
SCJP 1.4 90%, SCWCD5 94%, Next SCDJWS--> In Naescent stage. Researching abt exam and material itself.
Milton Ochoa
Ranch Hand

Joined: Oct 23, 2007
Posts: 336

the best you can do, is test this by your self.

If you have a problem implementing this, you can ask!!
Chithra Salam
Greenhorn

Joined: Mar 21, 2006
Posts: 19
Kamal Tripathi wrote:

On the same lines I wanted to ask if in a webapp's DD I configure an HttpSessionAttributeListener and also define a class A implementing HttpSessionBindingListener interface.

Now when objects of class A are set as attributes in session which listener will run first???
.

The Web container registers the listener instances according to the interfaces they implement and the order in which they appear in the deployment descriptor-means

If suppose a LisitenerclassA implements HttpSessionAttributeListener ,HttpSessionBindingListener and another class LisitenerclassB implements HttpSessionAttributeListener ,HttpSessionBindingListener

and in dd we declare
<listener><listener-class><com.example.LisitenerclassB ></listener-class></listener>
<listener><listener-class><com.example.LisitenerclassA></listener-class></listener>
Now order of creation of instance of classes is LisitenerclassB ,LisitenerclassA.
and then order of registration of classes for events are LisitenerclassB regstrd against HttpSessionAttributeListener
LisitenerclassB regstrd against HttpSessionBindingListener
LisitenerclassA regstrd against HttpSessionAttributeListener
LisitenerclassA regstrd against HttpSessionBindingListener .

So a HttpSessionAttribute event [replace an attribute including a binding event]occur LisitenerclassB will be notified 1st and method invocation will be in the order attributeReplaced,valueBound- means in the order in which interface is been regstrd.

Kamal Tripathi wrote:On the same lines I wanted to ask if in a webapp's DD I configure an HttpSessionAttributeListener and also define a class A implementing HttpSessionBindingListener interface.
--- When you say configure an HttpSessionAttributeListener in DD that includes that class A implements HttpSessionAttributeListener as well rght .I think now you got the answer for this as well.
Thanks,
Chithra Salam
SCJP-85%,SCWCD-in progress.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Listener Registration