In JSF, how will you make a managed bean as an eager application scoped bean?

In JSF, how will you make a managed bean as an eager application scoped bean?

Ninja Asked on 19th September 2018 in JSF.
Add Comment
1 Answer(s)
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 {

...

}

Ninja Answered on 19th September 2018.
Add Comment