users@glassfish.java.net

Re: POJO serialization between JSF managed bean and EJB session bean

From: <glassfish_at_javadesktop.org>
Date: Mon, 05 Nov 2007 12:39:19 PST

Yes, that's not a portable way to look up a Local (or remote) EJB. The portable way is to define an EJB dependency and look up the EJB reference via that dependency. It's a level of indirection that prevents your code from depending on a global JNDI name.

Add @EJB(name="myEjbRef", beanInterface=MyBeanInterface.class) to the class-level of your managed bean.

Then look up the EJB reference as follows :

 MyBeanInterface mbi = (MyBeanInterface) new InitialContext().lookup("java:comp/env/myEjbRef");

Note that the portion of the lookup string after java:comp/env/ matches the name() attribute of @EJB.
[Message sent by forum member 'ksak' (ksak)]

http://forums.java.net/jive/thread.jspa?messageID=243936