开发者

How to access a stateful bean in a listener

开发者 https://www.devze.com 2023-03-02 11:48 出处:网络
I have a Java EE project with an EJB containing a Remote Stateful Bean. I have an enterprise application with a GUI.

I have a Java EE project with an EJB containing a Remote Stateful Bean.

I have an enterprise application with a GUI.

I have listener in my GUI but my problem is that I can't access to my Bean in a button listener (to check username and password).

I use netBeans and glassFish.

To lookup beans I use:

ctx.lookup("java:comp/env/BeanStateful");

But ap开发者_如何学Pythonparently the listener change the context and it doesn't work anymore.


The listener is probably running on a thread that does not have a JavaEE context. Try obtaining the java:comp/env Context from the main thread, and then only lookup() the bean name from the listener. For example:

// Member variables
private Context _javaCompEnvContext;
...

// Main thread
_javaCompEnvContext = ctx.lookup("java:comp/comp/env");
...

// Listener thread
BusinessIntf bean = _javaCompEnvContext.lookup("BeanStateful");
0

精彩评论

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