Forums Register Login

Accessing a managed bean from within another managed bean

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
+Pie Number of slices to send: Send
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:
+Pie Number of slices to send: Send
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.
A tiny monkey bit me and I got tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 6759 times.
Similar Threads
Passing data between beans
how to trigger a servlet from JSF
commandLink param problem
Accessing JSF sesson bean from a servlet
AJAX (no framework), JSF Portlet w/ Managed Bean on WebSphere
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 22:22:33.