(forwarding reply that accidentally ended up off-list)
-------- Forwarded Message --------
From: simon <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Subject: Re: PhaseListener contruction in relation to FacesContext
Date: Fri, 20 Jun 2008 11:46:40 +0200

On Fri, 2008-06-20 at 11:39 +0200, Matthias Berndt wrote:
> On Fri, Jun 20, 2008 at 11:29:18AM +0200, simon wrote:
> > > Should a FacesContext exist at the moment, when a Phaselistener is
> > > contructed (Contructor called)?
> > 
> > Nope.
> > 
> 
> Thanks, I asked because I access the ServletContext using the
> FacesContext in the constructor to read some porperties. With JBoss and
> Glassfish FacesContext.getCurrentInstance() != null, but Tomcat returns
> null. (JSF-RI 1.2) I'd simply liked to know which is the correct
> behavior.
> 
> > A PhaseListener is an object that exists outside of any particular
> > request; the same instance is used for every request received by a
> > webapp.
> > 
> > A FacesContext instance is created for each request, and is discarded
> > when the request ends.
> > 
> > So there is no FacesContext when a PhaseListener is constructed; there
> > *is* a FacesContext available when any of the standard callback methods
> > on the PhaseListener is invoked.
> 
> So it seems that JBoss and Glassfish do more than expected.

Well, there are two types of PhaseListener: 
 * global ones (JSF1.1 and later)
 * per-view phase listeners (JSF1.2)
I'm talking about the traditional global one above. I don't know much
about the newer facility.

For the official definition of behaviour you would need to read the JSF
specification. But I cannot imagine how a valid FacesContext could be
created when a PhaseListener is instantiated. A FacesContext has methods
like
  * addMessage
  * getResponseStream
etc. What on earth would those methods do when called from the
constructor of a global PhaseListener, whose lifetime spans many
different requests?

Regards,
Simon

Reply via email to