myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject Re: how to execute one-time start-up code?
Date Fri, 18 May 2007 19:14:19 GMT
That worked. Thanks, Craig. 

"Craig McClanahan" <> 
Sent by:
05/18/2007 12:16 PM
Please respond to
"MyFaces Discussion" <>

"MyFaces Discussion" <>

Re: how to execute one-time start-up code?

On 5/18/07, <> wrote: 


Calling FacesContext.getCurrentInstance() returns null from my own 
ServletContextListener.contextInitialized(), even though I've written the 
web.xml like so: 


                <!-- Our context listener must come AFTER MyFaces's 
ContextListener --> 

This is using JBoss 4.x. Is there any way to force MyFaces' 
ContextListener to execute first?

Ordering will not make any difference, because there never will be a 
FacesContext at initialization time ... that only happens when a request 
comes in. 

However, you can still easilhy initialize application scope attributes, 
because your contextInitialized() method gets a n indirect reference to 
the ServletContext, so you can just store an attribute there.  Once you 
start processing requests, these attributes will be pre-existing 
application scope beans. 

    public void contextInitialized(ServletContextEvent event) {
        ServletContext context = event.getServletContext();
        Foo foo = new Foo(...);
        context.setAttribute("foo", foo); 




The information contained in this e-mail message is intended only for the 
exclusive use of the individual or entity named above and may contain 
information that is privileged, confidential or exempt from disclosure 
under applicable law. If the reader of this message is not the intended 
recipient, or the employee or agent responsible for delivery of the 
message to the intended recipient, you are hereby notified that any 
dissemination, distribution or copying of this communication is strictly 
prohibited. If you have received this communication in error, please 
notify the sender immediately by e-mail and delete the material from any 
computer.  Thank you.

View raw message