On 5/18/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> 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