Beans accessing other beans [message #475343] |
Tue, 04 December 2007 16:19  |
Eclipse User |
|
|
|
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 16:48  |
Eclipse User |
|
|
|
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 16:48  |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.27341 seconds