Two Laptop Bag
The moose likes JSF and the fly likes Initializing a managed bean at startup Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "Initializing a managed bean at startup" Watch "Initializing a managed bean at startup" New topic
Author

Initializing a managed bean at startup

Julien Martin
Ranch Hand

Joined: Apr 24, 2004
Posts: 383
Hello,
I have an application-scoped managed bean that takes quite a while to initialize and I would like for it to be initialized at startup time instead of the first loading of the page that uses it. I use tomcat.
I know there is no straightforward declarative way to do it see(http://www.jsfcentral.com/editorial/jsf2_wishlist_1.html) but I nevertheless wish for a programmatic way of achieving this perhaps using a servlet.
Can anyone help?
Thanks in advance,
Julien Martin.
Joseph Miller
Greenhorn

Joined: Jun 19, 2001
Posts: 21
Julien,

I stumbled across this blog post and wonder if it could help you. It describes how you can get to FacesContext when you're not within the context of JSF: blog post here
Once you have an instance of FacesContext, you can initialize the managed bean with EL:


One way to call this code on startup would be to place it in a servlet's init() method and deploy the servlet with the <load-on-startup> attribute.

hope that helps.

--
Joe
Julien Martin
Ranch Hand

Joined: Apr 24, 2004
Posts: 383
Hello Joseph,

The problem is that I call the following method in the managed bean:



and that the facescontext or the externalContext appear to be null even though I specified that the facesservlet should be initialized first.

I have an init servlet try to put the managed bean into the servletcontext.

I always get a nullpointerexception on the line marked npe.

Any idea?

Julien.
 
 
subject: Initializing a managed bean at startup
 
Threads others viewed
Facelets in JSF????
commandLink param problem
[ANNOUNCE] Recent JSFCentral Articles (JBoss, McClanahan, Dreamweaver)
ANNOUNCE: Stan Silvert on Testing JSF Applications with JSFUnit
[ANNOUNCE] JSF 2.0 Wish List
IntelliJ Java IDE