You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by im...@apache.org on 2008/02/07 10:56:23 UTC

svn commit: r619340 - in /myfaces/orchestra/trunk/core/src/main: java/org/apache/myfaces/orchestra/lib/jsf/FacesContextWrapper.java java/org/apache/myfaces/orchestra/lib/jsf/OrchestraFacesContextFactory.java resources/META-INF/faces-config.xml

Author: imario
Date: Thu Feb  7 01:56:23 2008
New Revision: 619340

URL: http://svn.apache.org/viewvc?rev=619340&view=rev
Log:
ORCHESTRA-15: Initialize Orchestra's FrameworkAdapter using the FacesContextFactory pattern which should make Orchestra play nicely in an portlet environment

Added:
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/FacesContextWrapper.java   (with props)
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/OrchestraFacesContextFactory.java   (with props)
Modified:
    myfaces/orchestra/trunk/core/src/main/resources/META-INF/faces-config.xml

Added: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/FacesContextWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/FacesContextWrapper.java?rev=619340&view=auto
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/FacesContextWrapper.java (added)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/FacesContextWrapper.java Thu Feb  7 01:56:23 2008
@@ -0,0 +1,150 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.myfaces.orchestra.lib.jsf;
+
+import javax.el.ELContext;
+import javax.faces.application.Application;
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseStream;
+import javax.faces.context.ResponseWriter;
+import javax.faces.render.RenderKit;
+import java.util.Iterator;
+
+
+/**
+ * Convenient class to wrap the current FacesContext.
+ * @author Manfred Geiler (latest modification by $Author$)
+ * @author Anton Koinov
+ * @version $Revision$ $Date$
+ */
+public class FacesContextWrapper extends FacesContext
+{
+    //~ Instance fields ----------------------------------------------------------------------------
+
+    private FacesContext _facesContext;
+
+    //~ Constructors -------------------------------------------------------------------------------
+
+    public FacesContextWrapper(FacesContext facesContext)
+    {
+        _facesContext = facesContext;
+    }
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    public Application getApplication()
+    {
+        return _facesContext.getApplication();
+    }
+
+    public Iterator getClientIdsWithMessages()
+    {
+        return _facesContext.getClientIdsWithMessages();
+    }
+
+    public ExternalContext getExternalContext()
+    {
+        return _facesContext.getExternalContext();
+    }
+
+    public FacesMessage.Severity getMaximumSeverity()
+    {
+        return _facesContext.getMaximumSeverity();
+    }
+
+    public Iterator getMessages()
+    {
+        return _facesContext.getMessages();
+    }
+
+    public Iterator getMessages(String clientId)
+    {
+        return _facesContext.getMessages(clientId);
+    }
+
+    public RenderKit getRenderKit()
+    {
+        return _facesContext.getRenderKit();
+    }
+
+    public boolean getRenderResponse()
+    {
+        return _facesContext.getRenderResponse();
+    }
+
+    public boolean getResponseComplete()
+    {
+        return _facesContext.getResponseComplete();
+    }
+
+    public void setResponseStream(ResponseStream responsestream)
+    {
+        _facesContext.setResponseStream(responsestream);
+    }
+
+    public ResponseStream getResponseStream()
+    {
+        return _facesContext.getResponseStream();
+    }
+
+    public void setResponseWriter(ResponseWriter responsewriter)
+    {
+        _facesContext.setResponseWriter(responsewriter);
+    }
+
+    public ResponseWriter getResponseWriter()
+    {
+        return _facesContext.getResponseWriter();
+    }
+
+    public void setViewRoot(UIViewRoot viewRoot)
+    {
+        _facesContext.setViewRoot(viewRoot);
+    }
+
+    public UIViewRoot getViewRoot()
+    {
+        return _facesContext.getViewRoot();
+    }
+
+    public void addMessage(String clientId, FacesMessage message)
+    {
+        _facesContext.addMessage(clientId, message);
+    }
+
+    public void release()
+    {
+        _facesContext.release();
+    }
+
+    public void renderResponse()
+    {
+        _facesContext.renderResponse();
+    }
+
+    public void responseComplete()
+    {
+        _facesContext.responseComplete();
+    }
+
+    public ELContext getELContext()
+    {
+        return _facesContext.getELContext();
+    }
+}

Propchange: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/FacesContextWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/FacesContextWrapper.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/FacesContextWrapper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/OrchestraFacesContextFactory.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/OrchestraFacesContextFactory.java?rev=619340&view=auto
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/OrchestraFacesContextFactory.java (added)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/OrchestraFacesContextFactory.java Thu Feb  7 01:56:23 2008
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.orchestra.lib.jsf;
+
+import org.apache.myfaces.orchestra.frameworkAdapter.FrameworkAdapter;
+import org.apache.myfaces.orchestra.frameworkAdapter.jsf.JsfFrameworkAdapter;
+
+import javax.faces.FacesException;
+import javax.faces.context.FacesContext;
+import javax.faces.context.FacesContextFactory;
+import javax.faces.lifecycle.Lifecycle;
+
+/**
+ * setup some aspects of the Orchestra framework
+ */
+public class OrchestraFacesContextFactory extends FacesContextFactory
+{
+	private final static String INIT_CONVERSATION_MESSAGER = "org.apache.myfaces.orchestra.CONVERSATION_MESSAGER"; // NON-NLS
+
+	private final FacesContextFactory original;
+
+	public OrchestraFacesContextFactory(FacesContextFactory original)
+	{
+		this.original = original;
+	}
+
+	public FacesContext getFacesContext(Object context, Object request, Object response, Lifecycle lifecycle) throws FacesException
+	{
+		FacesContext facesContext = original.getFacesContext(context, request, response, lifecycle);
+
+		if (facesContext != null && FrameworkAdapter.getCurrentInstance() == null)
+		{
+			String conversationMessager = facesContext.getExternalContext().getInitParameter(INIT_CONVERSATION_MESSAGER);
+			FrameworkAdapter.setCurrentInstance(new JsfFrameworkAdapter(conversationMessager));
+
+			FacesContext wrappedFaccesContext = new FacesContextWrapper(facesContext)
+			{
+				public void release()
+				{
+					super.release();
+
+					FrameworkAdapter.setCurrentInstance(null);
+				}
+			};
+
+			facesContext = wrappedFaccesContext;
+		}
+
+		return facesContext;
+	}
+}
\ No newline at end of file

Propchange: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/OrchestraFacesContextFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/OrchestraFacesContextFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/OrchestraFacesContextFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: myfaces/orchestra/trunk/core/src/main/resources/META-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/resources/META-INF/faces-config.xml?rev=619340&r1=619339&r2=619340&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/resources/META-INF/faces-config.xml (original)
+++ myfaces/orchestra/trunk/core/src/main/resources/META-INF/faces-config.xml Thu Feb  7 01:56:23 2008
@@ -45,6 +45,7 @@
 	</lifecycle>
 
 	<factory>
+		<faces-context-factory>org.apache.myfaces.orchestra.lib.jsf.OrchestraFacesContextFactory</faces-context-factory>
 		<faces-context-factory>org.apache.myfaces.orchestra.requestParameterProvider.jsf.RequestParameterFacesContextFactory</faces-context-factory>
 		<application-factory>org.apache.myfaces.orchestra.lib.jsf.OrchestraApplicationFactory</application-factory>
 	</factory>