wood burning stoves*
The moose likes JSF and the fly likes How to create managed beans at startup Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "How to create managed beans at startup" Watch "How to create managed beans at startup" New topic
Author

How to create managed beans at startup

Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
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

Joined: May 29, 2006
Posts: 63
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.


Hank
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
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

Joined: Sep 14, 2001
Posts: 85
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

Joined: Sep 16, 2005
Posts: 1780
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to create managed beans at startup
 
Similar Threads
Interview story
EJB vs Java Beans--design choice
JSF bean container
JPA and DAO pattern
Initialization of Managed Bean