Inject a EJB into a JSF converter with JEE6

Posted by Michael Bavin on Stack Overflow See other posts from Stack Overflow or by Michael Bavin
Published on 2010-01-07T10:12:29Z Indexed on 2010/06/14 22:32 UTC
Read the original article Hit count: 235

Hi,

I have a stateless EJB that acceses my database. I need this bean in a JSF 2 converter to retreive an entity object from the String value parameter. I'm using JEE6 with Glassfish V3

@EJB annotation does not work and gets a NPE, because it's in the faces context and it has not access to the ejb context.

My question is: Is it still possible to Inject this bean (With a @Resource or other annotation, a JNDI lookup,...), or do i need a workaround?

Thank you

Solution

Do a JNDI lookup like this:

try { ic = new InitialContext(); myejb= (MyEJB) ic .lookup("java:global/xxxx/MyEJB");
} catch (NamingException e) { e.printStackTrace(); }

© Stack Overflow or respective owner

Related posts about jsf

Related posts about j2ee