users@javaserverfaces.java.net

Re: Beans talking to other beans

From: Ryan Lubke <Ryan.Lubke_at_Sun.COM>
Date: Tue, 04 Dec 2007 18:41:02 -0800

Arinté 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?
The rule is that an application scoped bean cannot have a *managed
property* having a scope with a shorter lifetime.

>
> Right now I am doing this:
> FacesContext fc = FacesContext.getCurrentInstance();
> ValueExpression ve =
> fc.getApplication().getExpressionFactory().createValueExpression(fc.getELContext(),"#{user}",
> User.class);
> User u = (User)ve.getValue(fc.getELContext());
>
> Surely, there is a faster less verbose way?
>
Sure, use Application.evaluatedExpressionGet() [1].

[1]
http://java.sun.com/javaee/javaserverfaces/1.2_MR1/docs/api/javax/faces/application/Application.html#evaluateExpressionGet(javax.faces.context.FacesContext,%20java.lang.String,%20java.lang.Class)


> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_javaserverfaces.dev.java.net
> For additional commands, e-mail: users-help_at_javaserverfaces.dev.java.net
>