Inject a EJB into a JSF converter with JEE6
- by Michael Bavin
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();
}