myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Guy Katz" <>
Subject RE: managed beans creation facility question
Date Tue, 30 Aug 2005 06:05:27 GMT
hi and thanks for the responses.
sure, the FacesContext is a per request object. but as you guys mentioned in a possible solution
below, you can make FacesContext.getCurrentInstance().getExternalContext return the Servlet
or Portlet Context even if there is no request (hey, they exists...). this allows the code
to be portable across containers (portlet and servlet) cause now (after migrating to a ServletContext
solution) i guess my code will only work for servlet containers.

also, i dont see any problems with implementing a managed bean creation facility in a way
that will allow the application scope beans be initialized on startup (even if they use a
property through a value binding exp. if the bean is in the app scope then the value binding
exp it uses to initialize a propery must be in the app scope also anyway).
any thoughts?

-----Original Message-----
From: Craig McClanahan []
Sent: Monday, August 29, 2005 1:02 AM
To: MyFaces Discussion
Subject: Re: managed beans creation facility question

On 8/28/05, ir. ing. Jan Dockx <> wrote:
> Good point, I think, and no, I can't think of a rationale.

The key issue is that expression evaluation occurs with respect to a
context ... specifically, the FacesContext for the current request,
which contains internal references to (in a webapp) a ServletContext,
a ServletRequest, and a ServletResponse.  There can't be such a "real"
object at application startup time, because there is no request in

> You could work around the limitation by initializing the objects you
> need in a servlet context listener though, and store them in
> application scope yourself. You are not using the managed bean (~ IoC)
> mechanism then though.
> If, however, you just access the VariableResolver in your context
> listener, the beans get initialized and get stored in the scope they
> are defined for.

That won't necessarily be sufficient if your managed bean declaration
has managed properties that are also initialized via value binding
expressions.  The JSF framework will be applying its usual expression
evaluation facilities to that kind of an expression.

An alternative that might work, though, is to construct a mock
ExternalContext with only the ServletContext object, and no request
and response, and then construct a mock FacesContext wrapping that. 
You should be able to evaluate expressions that don't attempt to
access things from request or session scope.


View raw message