FAQ

On 5/18/07, 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

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 11 of 12 | next ›
Discussion Overview
groupusers @
categoriesmyfaces
postedMay 18, '07 at 1:31p
activeMay 18, '07 at 7:15p
posts12
users4
websitemyfaces.apache.org

People

Translate

site design / logo © 2017 Grokbase