This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I intend to load some data from the database and loading it into the application Scope Context once during the lifetime of my application so it can be used by every managed Bean. I considered putting this code inside a managed bean marked as Application Scoped. But i realise that the Application Scoped Managed Bean does not execute unless an JSF action references a method contained in it, so in essence if nothing references that Application Scoped Bean. it might never get called...Suggestions are welcome to resolve this [ October 23, 2007: Message edited by: Abiodun Adisa ]
1. Create a basic servlet set up to initialize on startup.
2. Add an init() method to the servlet that constructs the bean and stores it at application scope.
3. Use the normal JSF processes to reference this bean as needed.
There's no difference between beans constructed and stored by JSF code and their counterparts constructed and stored by non-JSF code. All JSF is doing here is handling the construction for you (if you ask it to).
An IDE is no substitute for an Intelligent Developer.
can you please elaborate this ?
i mean i can track the context initilized by ServletContextListner but how can i initilize a manage bean with fully blown dependencies, and how can i put this to application scope
can you please elaborate with sample ..
you can register a class which implements ServletContextListener (for Servlet API 2.5 in your web.xml descriptor) which is called when a web application is started or the application context is reloaded for example with the Tomcat manager application.
You can store the application scoped bean or something as a Servlet context attribute. The listener will automatically receive a ServletContextEvent which in turn gives you access to context attributes. Where you get your application specific dependencies from for the object to create is of course up to you.
Just have a look to the Servlet API documentation for the said listener. If you still have problems to find out how it works feel free to ask
Joined: Mar 05, 2009
i am getting 'var' as null at deployment time,
how to inject properties that i dont understand,
can you please tell me,
You only USE the context listener to create an application scoped object but the listener class itself is not the application scoped object! You create the said object inside the listener and store it as a Servlet context attribute. Unfortunately I don't even know how exactly you can access scoped objects inside JSF 1.x (I guess it's 1.x) but I'm sure there's an easy way to do so.
Have a look at the Servlet API. The ServletContextEvent gives you access to the ServletContext which in turn has a method "setAttribute()" which can be used to store context (=application) wide objects which can then be accessed from insided JSP or JSF pages.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com