aspose file tools
The moose likes JSF and the fly likes Accessing a managed bean from within another managed bean Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "Accessing a managed bean from within another managed bean" Watch "Accessing a managed bean from within another managed bean" New topic
Author

Accessing a managed bean from within another managed bean

Mike Litherland
Ranch Hand

Joined: Aug 12, 2004
Posts: 31
Hi,

I'm just starting out using JSF and I'm a bit confused. I'm writing a web app that has very complex user roles and everything you do within the app needs to be determined by your user role. As a result all of my commandButtons and commandLinks point to methods of my managed user bean which determines whether the user can perform a given action.

So far so good. Now I want my user to fill in a form that's backed by a different bean (in this case to add a new user). Only problem is I can't see how to get access to the different bean (let's call it the account bean) from within the user bean. I've looked at getting an instance of the FacesContext and played with the lifecycle stuff but I'm still stumped.

So here's my two questions - am I thinking about this the right way? And, how do I access my account bean within my user bean?

Thanks so much,
Mike
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780


There is no emoticon for what I am feeling!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 14491
    
    7

I've done some role-sensitive stuff in JSF, but it was simple enough not to consider farming out to a user properties class:



If you do want to centralize user info into a bean that logic bean(s) reference, the way to go is IoC. Both beans are managed beans, the logic bean is given session scope and the user info bean (also in session scope) is injected into the logic bean using the wiring functionality that's in the faces-config.xml file.

Here's some functionally-equivalent wiring, although instead of user properties, the injected bean contains captured search criteria:


Customer surveys are for companies who didn't pay proper attention to begin with.
Mike Litherland
Ranch Hand

Joined: Aug 12, 2004
Posts: 31
Thanks for the replies. I especially found the hint about the managed property useful, Tim. It's exactly what I was looking for. I may just get this JSF stuff yet.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Accessing a managed bean from within another managed bean
 
Similar Threads
commandLink param problem
Passing data between beans
AJAX (no framework), JSF Portlet w/ Managed Bean on WebSphere
how to trigger a servlet from JSF
Accessing JSF sesson bean from a servlet