This ApplicationScoped Named Bean is accessed mainly from a Facelet using JSF 2.0. It is ApplicationScoped becuase the data it holds is fairly small and is only very rarely updated. So whenever a "Status" is changed, I fire an Event<Status> from the class that changes it via a CRUD operation. When the StatusBackingBean is initially created and the @PostConstruct method is called, obviously the statusFacade (a StatelessSessionBean) in correctly injected and is not null. When the event fires when a "Status" object is changed, I want to reload all the statuses from the database, so that all users have a freshly updated list of Statuses. However when calling statusFacade.findAll(); in the method private void statusChanged(@Observes Status status) I get a NullPointerException stating that the StatusFacade is null.
Is it not true that in an ApplicationScoped Bean, injected Enterprise Beans should always have a reference to a valid instance. Why is it NULL when accessed for a second time when the statusChanged method is fired even though it is the same object every time? is the injected StatusFacade instance nulled right after the method annotated with "PostConstruct" returns?
I am using GlassFish 3 (with WELD), NetBeans 3.9.1
Joined: Apr 14, 2009
Ok I think I've got this one figured out:
Only a reference to the StatusBackingBean that is injected via CDI has a valid reference to the StatusFace SLSB, even though the object hashcode of the StatusBackingBean is the same throughout the entire Application. Seems to me that only the Proxy Object created when Injecting via CDI has an initialized Statusfacade an List of Statuses. It seems to me as if accessing any Field from the statusChanged method when the Event fires causes a NullPointerException because it is a different ProxyObject.