It's not a secret anymore!
The moose likes JSF and the fly likes JSF Managed Bean Injection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF Managed Bean Injection" Watch "JSF Managed Bean Injection" New topic

JSF Managed Bean Injection

Kumar Amit
Ranch Hand

Joined: Aug 13, 2001
Posts: 103
Hi Friends,
Any idea whether we can Inject one JSF managed bean as a property into another JSF backing bean/managed bean?

I am trying to create a layer of abstraction between my backing beans and ejbs by creating a single managed bean that will have @EJB annotation to invoke the bean. This is my version of business delegate or service layer.
JSF Backing Bean -> JSF ManagedBean (Coordinator) ->EJB

Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33102

Moved to the JSF forum. Even though you are asking due to the exam, it's a fairly specific JSF question and someone here is more likely to know.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
M. A. Riveros T.
Ranch Hand

Joined: May 16, 2011
Posts: 46


Kumar Amit
Ranch Hand

Joined: Aug 13, 2001
Posts: 103
M. A. Riveros T. wrote:


Thanks Riveros. Can I have both these managed beans as "request scoped"?

Also can i use "@EJB" annotation in "ToBeInjected" managed bean class after making request scoped.


Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17410

The rule on injection is that you can't inject an object whose lifespan is shorter than the target.

JSF is not very friendly to request-scope objects, however, so you can't use them as often as you would in most web frameworks.

Injecting EJBs into JSF backing/managed beans is possible, but rarely a good idea, since you're injecting a specific instance statically declared, and most of the time you want the EJBs to be more dynamic than that.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: JSF Managed Bean Injection
It's not a secret anymore!