File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes can I inject ejb into managed bean? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "can I inject ejb into managed bean?" Watch "can I inject ejb into managed bean?" New topic

can I inject ejb into managed bean?

Jiaxu Gu

Joined: Oct 29, 2005
Posts: 12
I tried to inject a stateless session bean into the JSF managed bean using netbeans 6.1+glassfish v2.
First I create an enterprise application with an ejb module and a web module,then create a Remote stateless session bean in the ejb module,and add a business method.
Next I add JSF Framework to the web module and add a java class and using netbeans context menu to config it as the managed bean in the face-config.xml,then I open the managed bean class and select context menu :enterprise resource->call enterprise bean and select the session bean I created. After that these two lines add to the file

but when I use the managed bean , I found the testBean is null.

I have search the web and found some usage(DI) like this,
Are there something wrong with what I'm doing?

ps:I know the Seam framework and the jndi lookup can fix it,
but here I just want to know why can't I inject ejb into my managed bean?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17410

The JSF bean manager isn't as comprehensive as something like Spring. It's intended to create POJOs via no-argument constructors, not via factory/finder techniques. That's your first problem.

I'm not sure, but the idea of injecting a stateless session bean sounds questionable, anyway. Normally, as I recall (they haven't let me use EJBs where I work), a stateless session EJB is acquired from a pool, used, and released fairly quickly, not locked down and held. So, while injecting a SSEJB into a Request-scope object is OK, it wouldn't be suitable for a Session or Application scope object.

An IDE is no substitute for an Intelligent Developer.
jQuery in Action, 3rd edition
subject: can I inject ejb into managed bean?
jQuery in Action, 3rd edition