Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding order of listener elements

 
Vedhas Pitkar
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,the JSP spec states in JSP7.1.2.2 that the order in which the listeners are registered is undefined.
But I have read in H.Deshmukh's study guide that
if there are 2 listener elements then their implementation classes will be called in the order in wich they appear in web.xml.
Viz.
<listener>
<listener-class>
MyListener
</listener-class>
</listener>
<listener>
<listener-class>
YourListener
</listener-class>
</listener>
Then MyListener will be called first then YourListener.
Doesnt this contradict the specs?Or am I missing something?
 
Mikalai Zaikin
Ranch Hand
Posts: 3371
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vedhas,
it seems you mixed up 2 things:
1) tag library descriptor, which can has listeners defined
2) web application deployment descriptor, which also can contain listener definitions inside
cheers.
 
Maha Annadurai
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vedhas,
Both Spec and Hanumanth's info are right.
The order of listeners in web.xml does matter.
Jsp container finds all the *.tld files in web app, and grabs all the listerners inside them and does an auto registration to web.xml. What the spec says is, it does not gurantee the order in which it will register them into web.xml. Every time you restart the jsp container, the order may be different and consquently, the order in which the taglib listeners called for events may vary.

Here is the spec :
A tag library may include classes that are event listeners (see the Servlet 2.3
specification). The listeners classes are listed in the tag library descriptor and the
JSP container automatically instantiates them and registers them. A container is
required to locate all TLD files (see Section JSP.7.3.1 for details on how they are
identified), read their listener elements, and treat the event listeners as extensions of
those listed in web.xml.
The order in which the listeners are registered is undefined, but they are
registered before application start.
Regards,
Maha Anna
[ November 23, 2002: Message edited by: Maha Annadurai ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic