Does JSF Managed Bean scope impacts visibility & access between EAR, WAR and JAR

403 Views Asked by At

I have EAR with in Which WAR & few JARS. Eventually few more JARS under my WAR too.

I have packaged a set of DATA OBJECTs inside a EAR as JAR, out which one of its Managed Bean is under 'SessionScope' and with its property -> 'eager = true'. Say 'A.Java'

Now, From My WAR I have a ManagedBean, say 'B.java', with 'RequestScope' trying to get an instance of A.java, Which is returned as NULL. From the Logs, When traced got the below exception:

The managed-bean with name 'B' must be application scoped to support eager=true.

Is there a hierarchy of Managed Bean Scope, that we have to ensure while archiving and deploying as EAR???

1

There are 1 best solutions below

2
On

Eager Application-Scoped Beans

Managed beans are lazily instantiated. That is, that they are instantiated 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

The eager property means that the container creates the instance at application startup and not on demand. It can put this instance just into the application scope. (There are no other scopes at this time). So the eagerly created managed beans must be ApplicationScoped.