org.apache.myfaces.orchestra.lib.jsf
Class _FacesContextWrapper

java.lang.Object
  extended by javax.faces.context.FacesContext
      extended by org.apache.myfaces.orchestra.lib.jsf._FacesContextWrapper

public class _FacesContextWrapper
extends javax.faces.context.FacesContext

Convenient class to wrap the current FacesContext.

A class of this name is provided in JSF1.2, but not in JSF1.1.

Any methods that do not actually need to be overridden are declared final in order to improve performance (helps the JVM to optimise away the call).

Note that whether a newly-created instance immediately becomes the object that is returned by FacesContext.getCurrentInstance() depends upon the value of the "install" parameter for the constructor method.

This class is copied from the code in MyFaces Core Impl 1.2.x, but modified to be compatible with JSF1.1.

Note that this class must be public in order to support custom FacesContextFactory classes in other libraries that also wrap this instance, then use reflection to invoke methods on this object. In this case, an IllegalAccessException would occur if this class was package-scoped. However this class is NOT intended to be part of the public Orchestra API, and may change at any time.

Since:
1.1
Version:
$Revision: 672906 $ $Date: 2008-06-30 15:45:16 -0500 (Mon, 30 Jun 2008) $
Author:
Manfred Geiler (latest modification by $Author: skitching $), Anton Koinov

Constructor Summary
_FacesContextWrapper(javax.faces.context.FacesContext facesContext, boolean install)
          The install parameter controls whether this object will be configured as the object returned from calls to FacesContext.getCurrentInstance() or not.
 
Method Summary
 void addMessage(String clientId, javax.faces.application.FacesMessage message)
           
 javax.faces.application.Application getApplication()
           
 Iterator getClientIdsWithMessages()
           
 javax.el.ELContext getELContext()
          Implement getELContext by delegating call to another instance.
 javax.faces.context.ExternalContext getExternalContext()
           
 javax.faces.application.FacesMessage.Severity getMaximumSeverity()
           
 Iterator getMessages()
           
 Iterator getMessages(String clientId)
           
 javax.faces.render.RenderKit getRenderKit()
           
 boolean getRenderResponse()
           
 boolean getResponseComplete()
           
 javax.faces.context.ResponseStream getResponseStream()
           
 javax.faces.context.ResponseWriter getResponseWriter()
           
 javax.faces.component.UIViewRoot getViewRoot()
           
 void release()
           
 void renderResponse()
           
 void responseComplete()
           
 void setResponseStream(javax.faces.context.ResponseStream responsestream)
           
 void setResponseWriter(javax.faces.context.ResponseWriter responsewriter)
           
 void setViewRoot(javax.faces.component.UIViewRoot viewRoot)
           
 
Methods inherited from class javax.faces.context.FacesContext
getCurrentInstance, setCurrentInstance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

_FacesContextWrapper

public _FacesContextWrapper(javax.faces.context.FacesContext facesContext,
                            boolean install)
The install parameter controls whether this object will be configured as the object returned from calls to FacesContext.getCurrentInstance() or not.

When only overriding the release() method, then install=false is ok as that is called directly by the FacesServlet on the instance returned by the FacesContextFactory. However all other methods are invoked on the object that is returned from FacesContext.getCurrentInstance, so install=true is needed in order for any other method overrides to have any effect.

IMPORTANT: install=true should not be used until MYFACES-1820 is fixed.

Method Detail

release

public void release()
Specified by:
release in class javax.faces.context.FacesContext

getApplication

public final javax.faces.application.Application getApplication()
Specified by:
getApplication in class javax.faces.context.FacesContext

getClientIdsWithMessages

public final Iterator getClientIdsWithMessages()
Specified by:
getClientIdsWithMessages in class javax.faces.context.FacesContext

getExternalContext

public final javax.faces.context.ExternalContext getExternalContext()
Specified by:
getExternalContext in class javax.faces.context.FacesContext

getMaximumSeverity

public final javax.faces.application.FacesMessage.Severity getMaximumSeverity()
Specified by:
getMaximumSeverity in class javax.faces.context.FacesContext

getMessages

public final Iterator getMessages()
Specified by:
getMessages in class javax.faces.context.FacesContext

getMessages

public final Iterator getMessages(String clientId)
Specified by:
getMessages in class javax.faces.context.FacesContext

getRenderKit

public final javax.faces.render.RenderKit getRenderKit()
Specified by:
getRenderKit in class javax.faces.context.FacesContext

getRenderResponse

public final boolean getRenderResponse()
Specified by:
getRenderResponse in class javax.faces.context.FacesContext

getResponseComplete

public final boolean getResponseComplete()
Specified by:
getResponseComplete in class javax.faces.context.FacesContext

setResponseStream

public final void setResponseStream(javax.faces.context.ResponseStream responsestream)
Specified by:
setResponseStream in class javax.faces.context.FacesContext

getResponseStream

public final javax.faces.context.ResponseStream getResponseStream()
Specified by:
getResponseStream in class javax.faces.context.FacesContext

setResponseWriter

public final void setResponseWriter(javax.faces.context.ResponseWriter responsewriter)
Specified by:
setResponseWriter in class javax.faces.context.FacesContext

getResponseWriter

public final javax.faces.context.ResponseWriter getResponseWriter()
Specified by:
getResponseWriter in class javax.faces.context.FacesContext

setViewRoot

public final void setViewRoot(javax.faces.component.UIViewRoot viewRoot)
Specified by:
setViewRoot in class javax.faces.context.FacesContext

getViewRoot

public final javax.faces.component.UIViewRoot getViewRoot()
Specified by:
getViewRoot in class javax.faces.context.FacesContext

addMessage

public final void addMessage(String clientId,
                             javax.faces.application.FacesMessage message)
Specified by:
addMessage in class javax.faces.context.FacesContext

renderResponse

public final void renderResponse()
Specified by:
renderResponse in class javax.faces.context.FacesContext

responseComplete

public final void responseComplete()
Specified by:
responseComplete in class javax.faces.context.FacesContext

getELContext

public final javax.el.ELContext getELContext()
Implement getELContext by delegating call to another instance.

Note that this method was added in JSF1.2. In order for a JSF1.2 implementation to be backwards-compatible with JSF1.1, the base class FacesContext therefore has to automatically do the delegation. Without automatic delegation, any JSF1.1 class that applies the decorator pattern to a FacesContext will just break in JSF1.2; the getELContext method is there (inherited from the base class) but does not correctly delegate.

Unfortunately, due to a design flaw in JSF1.2 it is simply not possible for the base class to delegate; the object to delegate to is not known to the base class! A partial solution that works in most cases is for the base class to delegate to the "core" instance of FacesContext for methods that are not overridden; Sun's RI does this correctly but unfortunately MyFaces 1.2.0-1.2.2 do not. See MYFACES-1820 for details.

The solution *here* is to require that a javax.el implementation is in the classpath even when running JSF1.1. It is then possible for this wrapper to override the method defined in JSF1.2 even when being compiled against the JSF1.1 implementation. It is mildly annoying to have to include javax.el in a JSF environment (ie when it will never be used) but better than the alternatives. Actually, for at least some JVMs, classes needed by a method are not loaded unless that method is actually referenced, so in some cases (including Sun Java 1.4-1.6) the el library *can* be omitted from the classpath with JSF1.1.



Copyright © 2012 The Apache Software Foundation. All Rights Reserved.