myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jak...@apache.org
Subject svn commit: r991889 - in /myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp: PseudoFacesContext.java TrinidadFilterImpl.java
Date Thu, 02 Sep 2010 11:13:36 GMT
Author: jakobk
Date: Thu Sep  2 11:13:35 2010
New Revision: 991889

URL: http://svn.apache.org/viewvc?rev=991889&view=rev
Log:
TRINIDAD-1902 Provide FacesContext for configuration tasks

Modified:
    myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/PseudoFacesContext.java
    myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/TrinidadFilterImpl.java

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/PseudoFacesContext.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/PseudoFacesContext.java?rev=991889&r1=991888&r2=991889&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/PseudoFacesContext.java
(original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/PseudoFacesContext.java
Thu Sep  2 11:13:35 2010
@@ -20,8 +20,13 @@ package org.apache.myfaces.trinidadinter
 
 import java.util.Iterator;
 
+import javax.el.ELContext;
+import javax.el.ELResolver;
+import javax.el.FunctionMapper;
+import javax.el.VariableMapper;
 import javax.faces.FactoryFinder;
 import javax.faces.application.Application;
+import javax.faces.application.ApplicationFactory;
 import javax.faces.application.FacesMessage;
 import javax.faces.component.UIViewRoot;
 import javax.faces.context.ExternalContext;
@@ -47,6 +52,17 @@ class PseudoFacesContext extends FacesCo
     _external = ec;
   }
 
+  public void setAsCurrentInstance()
+  {
+      FacesContext.setCurrentInstance(this);
+  }
+
+  @Override
+  public void release()
+  {
+    FacesContext.setCurrentInstance(null);
+  }
+
   @Override
   public ResponseWriter getResponseWriter()
   {
@@ -90,12 +106,6 @@ class PseudoFacesContext extends FacesCo
   }
 
   @Override
-  public Application getApplication()
-  {
-    throw new UnsupportedOperationException();
-  }
-
-  @Override
   public UIViewRoot getViewRoot()
   {
     throw new UnsupportedOperationException();
@@ -108,12 +118,6 @@ class PseudoFacesContext extends FacesCo
   }
 
   @Override
-  public ExternalContext getExternalContext()
-  {
-    return _external;
-  }
-
-  @Override
   public RenderKit getRenderKit()
   {
      throw new UnsupportedOperationException();
@@ -144,12 +148,6 @@ class PseudoFacesContext extends FacesCo
   }
 
   @Override
-  public void release()
-  {
-    throw new UnsupportedOperationException();
-  }
-
-  @Override
   public void renderResponse()
   {
     throw new UnsupportedOperationException();
@@ -162,6 +160,35 @@ class PseudoFacesContext extends FacesCo
   }
 
   @Override
+  public Application getApplication()
+  {
+    if (_application == null)
+    {
+        _application = ((ApplicationFactory) FactoryFinder.getFactory(
+                FactoryFinder.APPLICATION_FACTORY)).getApplication();
+    }
+
+    return _application;
+  }
+
+  @Override
+  public ELContext getELContext()
+  {
+    if (_elContext == null)
+    {
+      _elContext = new MockELContext(getApplication());
+    }
+
+    return _elContext;
+  }
+
+  @Override
+  public ExternalContext getExternalContext()
+  {
+    return _external;
+  }
+
+  @Override
   public PartialViewContext getPartialViewContext() 
   {
 
@@ -176,4 +203,38 @@ class PseudoFacesContext extends FacesCo
 
   private PartialViewContext _partialViewContext;
   private final ExternalContext _external;
+  private ELContext _elContext;
+  private Application _application;
+
+
+  // This is used to mock up a dummy ELContext to pass into createValueExpression
+  // if the FacesContext is null and we can't get FacesContext.getELContext.
+  private static class MockELContext extends ELContext
+  {
+    public MockELContext(Application application)
+    {
+      _resolver = application.getELResolver();
+    }
+
+    @Override
+    public ELResolver getELResolver()
+    {
+      return _resolver;
+    }
+
+    @Override
+    public FunctionMapper getFunctionMapper()
+    {
+      return null;
+    }
+
+    @Override
+    public VariableMapper getVariableMapper()
+    {
+      return null;
+    }
+
+    private final ELResolver _resolver;
+  }
+
 }

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/TrinidadFilterImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/TrinidadFilterImpl.java?rev=991889&r1=991888&r2=991889&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/TrinidadFilterImpl.java
(original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/TrinidadFilterImpl.java
Thu Sep  2 11:13:35 2010
@@ -26,9 +26,11 @@ import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 
+import javax.faces.FactoryFinder;
 import javax.faces.component.UIViewRoot;
 import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
+import javax.faces.context.FacesContextFactory;
 import javax.servlet.Filter;
 import javax.servlet.FilterChain;
 import javax.servlet.FilterConfig;
@@ -151,6 +153,10 @@ public class TrinidadFilterImpl implemen
                                         request,
                                         response);
 
+    // provide a (Pseudo-)FacesContext for configuration tasks
+    PseudoFacesContext facesContext = new PseudoFacesContext(externalContext);
+    facesContext.setAsCurrentInstance();
+    
     GlobalConfiguratorImpl config = GlobalConfiguratorImpl.getInstance();
     config.beginRequest(externalContext);
     
@@ -172,6 +178,9 @@ public class TrinidadFilterImpl implemen
       request = new UploadRequestWrapper((HttpServletRequest)request, addedParams);
     }
 
+    // release the PseudoFacesContext, since _doFilterImpl() has its own FacesContext
+    facesContext.release();
+
     try
     {
       _doFilterImpl(request, response, chain);



Mime
View raw message