开发者

component.getInstance() returns new instance in Seam

开发者 https://www.devze.com 2023-02-05 09:19 出处:网络
I\'ve been having a lot of trouble injecting components in Seam. When a certain user does something in my application I would like an event to be propagated to a number of other users currently logge

I've been having a lot of trouble injecting components in Seam.

When a certain user does something in my application I would like an event to be propagated to a number of other users currently logged (the users that receive the event will be decided by the user who caused the event to fire).

The way I've approached this is to create an object in Application scope with a HashMap story a stateful sessio开发者_如何转开发n bean against the user id.

When the event in fired, an observer method in the Application-scoped object runs and calls a method on each bean in the hashmap (passing as an argument an entity bean).

In the method called on each bean, I need to access some injected methods to verify if the "bean's user" should react to that event (by display some data from the entity bean). To do this I need access to some injected beans (both SFSB and stateless beans) but they're all null at this point.

My understanding is that Component.getInstance() (wrapped in a Lifecycle.beginCall() / .endCall() block) or one of the similar methods can be used here to retrieve the object however this doesn't work.

If I were to do something like (StoryManagerAction) Component.getInstance("storyManagerAction") where storyManagerAction is a stateful session bean I would expect that the the instance of StoryManagerAction named storyManagerAction currently residing in the session be returned. Instead, however, I'm getting an instance of StoryManagerAction with all its primitive members set as 0 and all its object members set as null.

Any idea why this is happening and what I need to do get this working properly?


When you iterate the Map and call the method on each StoryManagerAction what gets injected is relative to the scopes of the session who raised the event, not the scopes of the session the StoryManagerAction bean belongs to.

Avoid injection in StoryManagerAction and resolve all needed beans in a @Create annotated method where you will save the value in regular instance variables.

0

精彩评论

暂无评论...
验证码 换一张
取 消