H. Swaczinna wrote:
Hello,I want to load an application scoped bean immidiately when the applcation is loaded (deployed), not when it is first accessed. In general, I can create the bean in a ServletContextListener: public void contextInitialized(ServletContextEvent event) { LOG.debug("*** contextInitialized ***"); ServletContext servletContext = event.getServletContext(); MasterDataSupplier masterDataSupplier = new MasterDataSupplier(); servletContext.setAttribute("masterDataSupplier", masterDataSupplier); } But my question is, how do I resolve the managed properties of the bean? I can use a context-param for a simple string property but there're complex properties to handle (DAOs managed by Spring). I think, I have to get the (Sring)VariableResolver somehow and do the resolving myself. Has anybody done this before?
One option would be to use spring 2.0 instead of JSF managed beans. I believe that because Spring 2.0 supports "scopes" (request/session/application) it can now be used as a complete replacement for the half-baked JSF solution. And Spring beans are created on initialisation unless explicitly marked "lazy".
Unfortunately using the VariableResolver and similar from a ServletContextListener is tricky; the variable stuff all relies on having a FacesContext parameter. There is some info on the wiki about creating a FacesContext instance (see refs below).
An alternative would be a PhaseListener, where a FacesContext is easily available. Unfortunately the phase-listener will run on every request even though you only care about the very first time. It should be possible, though, for the phase-listener to remove itself after the first run.
The wiki has lots of useful info: http://wiki.apache.org/myfaces/ In particular, see: http://wiki.apache.org/myfaces/AccessFacesContextFromServlet http://wiki.apache.org/myfaces/AccessingOneManagedBeanFromAnother Regards, Simon

