myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eric.j...@novartis.com
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" <craigmcc@apache.org> 
Sent by: craigmcc@gmail.com
05/18/2007 12:16 PM
Please respond to
"MyFaces Discussion" <users@myfaces.apache.org>


To
"MyFaces Discussion" <users@myfaces.apache.org>
cc

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








On 5/18/07, eric.jung@novartis.com <eric.jung@novartis.com> wrote: 

Hi, 

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

        <listener> 
 
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>


        </listener> 
 
        <listener> 
                <!-- Our context listener must come AFTER MyFaces's 
ContextListener --> 
 <listener-class>com.myco.MyServletContextListener</listener-class> 
        </listener> 

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); 
    }

Craig


_________________________

CONFIDENTIALITY NOTICE

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.

Mime
View raw message