Mathieu,

I'd just configure them in a ServletContextListener. Just create the objects
and store them in the Servlet context (application scope). Spring makes
sense, but it's overkill just for this bit of functionality. If, however,
you really want the features that Spring provides (as a full-fledged
dependency injection container), then consider using Spring for your managed
beans.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Kito D. Mann - Author, JavaServer Faces in Action
http://www.virtua.com - JSF/Java EE consulting, training, and mentoring
http://www.JSFCentral.com - JavaServer Faces FAQ, news, and info

> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Sent: Thursday, March 20, 2008 6:38 AM
> To: MyFaces Development
> Subject: Re: question about managed bean
> 
> mathieu fabre schrieb:
> > Hi,
> >
> > I use JSF and MyFace in a webapp. I use some managed bean ( declared
> > in the
> > face-config.xml)
> > I would like to know if it's possible to create a managed bean at the
> > begining (like a tag <load-on-startup> we can use in servlet)
> > and not only when requested for the first time...
> 
> Not with the standard JSF managed-beans functionality.
> 
> I presume that this is an application-scope bean (anything else would
> not make sense to create on startup). In this case, you could use a
> servlet or servlet-context-listener to just add an entry into the
> standard application scope for the webapp; a JSF EL expression will
> find
> it there if it exists even though it is not defined as a managed-bean
> in
> the faces-config.xml file.
> 
> If you really want to define it in the faces-config.xml file (eg to
> configure it via dependency injection) then it is possible by having a
> ServletContextListener that sets up a FacesContext instance, then loads
> the bean manually. But that is not trivial.
> 
> But the easiest solution of all would be to use Spring to define your
> managed beans rather than the JSF built-in managed-beans configuration.
> This gives a whole lot of really useful features, one of which is the
> ability to create beans on startup. There is a page on the myfaces wiki
> about this:
>   http://wiki.apache.org/myfaces/JSF_With_Spring
> 
> Regards,
> Simon

Reply via email to