In JSF, how will you make a managed bean as an eager application scoped bean?
Answered
In JSF, how will you make a managed bean as an eager application scoped bean?
Best answer
Managed beans are lazily instantiated. That is, they are instantiated when a request is made from the application. For example, an application managed scope bean can be created using
@ManagedBean @ApplicationScoped public class DemoBean { ... }
This bean is instantiated only when a request is made from the application.
To force an application-scoped bean to be instantiated and placed in the application scope as soon as the application is started and before any request is made, the eager attribute of the managed bean should be set to true as shown in the following example:
@ManagedBean(eager=true) @ApplicationScoped public class DemoBean { ... }