Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JavaServer Faces » Beans accessing other beans
Beans accessing other beans [message #475343] Tue, 04 December 2007 21:19 Go to next message
Eclipse UserFriend
Originally posted by: arintejr.gmail.com

Ok so a rule states that a bean set to application cannot access a bean that is
set to request. But my question is what is the easiest/cleanest way for one
bean to get access to another?

Right now I am doing this:
FacesContext fc = FacesContext.getCurrentInstance();
ValueExpression ve =
fc.getApplication().getExpressionFactory().createValueExpres sion(fc.getELContext(), "#{user}",
User.class);
User u = (User)ve.getValue(fc.getELContext());

Surely, there is a faster less verbose way?
Re: Beans accessing other beans [message #475344 is a reply to message #475343] Tue, 04 December 2007 21:48 Go to previous message
Yury Kats is currently offline Yury KatsFriend
Messages: 104
Registered: July 2009
Senior Member
On 12/4/2007 4:19 PM, Arinte' wrote:
> Ok so a rule states that a bean set to application cannot access a bean that is
> set to request. But my question is what is the easiest/cleanest way for one
> bean to get access to another?
>
> Right now I am doing this:
> FacesContext fc = FacesContext.getCurrentInstance();
> ValueExpression ve =
> fc.getApplication().getExpressionFactory().createValueExpres sion(fc.getELContext(), "#{user}",
> User.class);
> User u = (User)ve.getValue(fc.getELContext());
>
> Surely, there is a faster less verbose way?

Not really the right forum for JSF usage questions, but your code is the correct
generic way to access a managed bean. If you knew what scope the bean is in and
didn't care about the bean being created when it isn't there, then you could
grab it directly from the appropriate scope's map.
Re: Beans accessing other beans [message #615740 is a reply to message #475343] Tue, 04 December 2007 21:48 Go to previous message
Yury Kats is currently offline Yury KatsFriend
Messages: 104
Registered: July 2009
Senior Member
On 12/4/2007 4:19 PM, Arinte' wrote:
> Ok so a rule states that a bean set to application cannot access a bean that is
> set to request. But my question is what is the easiest/cleanest way for one
> bean to get access to another?
>
> Right now I am doing this:
> FacesContext fc = FacesContext.getCurrentInstance();
> ValueExpression ve =
> fc.getApplication().getExpressionFactory().createValueExpres sion(fc.getELContext(), "#{user}",
> User.class);
> User u = (User)ve.getValue(fc.getELContext());
>
> Surely, there is a faster less verbose way?

Not really the right forum for JSF usage questions, but your code is the correct
generic way to access a managed bean. If you knew what scope the bean is in and
didn't care about the bean being created when it isn't there, then you could
grab it directly from the appropriate scope's map.
Previous Topic:Beans accessing other beans
Next Topic:Why needs to have a MetaDataModelManager per project?
Goto Forum:
  


Current Time: Tue Apr 16 03:56:39 GMT 2024

Powered by FUDForum. Page generated in 0.23956 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top