Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Initializing a managed bean at startup  RSS feed

 
Julien Martin
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!