Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to create managed beans at startup

 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have some application-scoped managed beans that I'm defining in my faces config file. So far, so good, that's all standard. But I'd like them to be instanciated at application start-up, rather than later when they happen to be first referenced. Is there a standard way to trigger their creation at application start-up?
 
Henry Lowell
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suppose you could create a context listener that you map in your web.xml and you could instantiate and throw all the managed beans into app scope. Just make sure you give them the same reference name as you do in your managed bean.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Henry Lowell:
I suppose you could create a context listener that you map in your web.xml and you could instantiate and throw all the managed beans into app scope. Just make sure you give them the same reference name as you do in your managed bean.


I think the problem with using a context listener is that if I try to get the FacesContext in it:

FacesContext context = FacesContext.getCurrentInstance();

You will get null.

And if I just directly instantiate my classes and add them to the application scope, I will be missing out on all the managed property values I define in my faces-config.xml, which is the whole reason I'm going through this execise! So this approach doesn't seem hopeful.
 
g madhava
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at the below link,it gives you an idea of how to get a handle on the FacesContext.

http://www.thoughtsabout.net/blog/archives/000033.html

P.S: I was going to try it out, but because of a change in the technical architecture, I didn't had the necessity to try it. Please let us know if the above idea worked out for you.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by g madhava:
Take a look at the below link,it gives you an idea of how to get a handle on the FacesContext.

http://www.thoughtsabout.net/blog/archives/000033.html

P.S: I was going to try it out, but because of a change in the technical architecture, I didn't had the necessity to try it. Please let us know if the above idea worked out for you.


Thanks for the tip. I'll look at it today.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic