myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ima...@apache.org
Subject svn commit: r552205 - /myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/frameworkAdapter/JsfFrameworkAdapter.java
Date Sat, 30 Jun 2007 20:10:18 GMT
Author: imario
Date: Sat Jun 30 13:10:17 2007
New Revision: 552205

URL: http://svn.apache.org/viewvc?view=rev&rev=552205
Log:
Use faces context first to get any jsf level decorated request/response/session map, fallback
to direct request/response handling only if there is no facesContext available. Thanks to
Michael Marr to provide a test case for the icefaces problem.

Modified:
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/frameworkAdapter/JsfFrameworkAdapter.java

Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/frameworkAdapter/JsfFrameworkAdapter.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/frameworkAdapter/JsfFrameworkAdapter.java?view=diff&rev=552205&r1=552204&r2=552205
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/frameworkAdapter/JsfFrameworkAdapter.java
(original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/frameworkAdapter/JsfFrameworkAdapter.java
Sat Jun 30 13:10:17 2007
@@ -36,14 +36,11 @@
  */
 public class JsfFrameworkAdapter implements FrameworkAdapterInterface
 {
+	private final static String ISE_MESSAGE="can't find a way to access jsf data structures";
// NON-NLS
+
 	protected FacesContext getFacesContext()
 	{
-		FacesContext context = FacesContext.getCurrentInstance();
-		if (context == null)
-		{
-			throw new IllegalStateException("no facesContext");
-		}
-		return context;
+		return FacesContext.getCurrentInstance();
 	}
 
 	public String getInitParameter(String key)
@@ -55,45 +52,64 @@
 
 	public Object getRequestParameterAttribute(String key)
 	{
+		FacesContext context = getFacesContext();
+		if (context != null)
+		{
+			return context.getExternalContext().getRequestParameterMap().get(key);
+		}
+
 		HttpServletRequest request = OrchestraServletFilter.getHttpServletRequest();
 		if (request != null)
 		{
 			return request.getParameter(key);
 		}
 
-		FacesContext context = getFacesContext();
-
-		return context.getExternalContext().getRequestParameterMap().get(key);
+		throw new IllegalStateException(ISE_MESSAGE);
 	}
 
 	public boolean containsRequestParameterAttribute(String key)
 	{
+		FacesContext context = getFacesContext();
+		if (context != null)
+		{
+			return context.getExternalContext().getRequestParameterMap().containsKey(key);
+		}
+
 		HttpServletRequest request = OrchestraServletFilter.getHttpServletRequest();
 		if (request != null)
 		{
 			return request.getParameter(key) != null;
 		}
 
-		FacesContext context = getFacesContext();
-
-		return context.getExternalContext().getRequestParameterMap().containsKey(key);
+		throw new IllegalStateException(ISE_MESSAGE);
 	}
 
 	public Object getRequestAttribute(String key)
 	{
+		FacesContext context = getFacesContext();
+		if (context != null)
+		{
+			return context.getExternalContext().getRequestMap().get(key);
+		}
+
 		HttpServletRequest request = OrchestraServletFilter.getHttpServletRequest();
 		if (request != null)
 		{
 			return request.getAttribute(key);
 		}
 
-		FacesContext context = getFacesContext();
-
-		return context.getExternalContext().getRequestMap().get(key);
+		throw new IllegalStateException(ISE_MESSAGE);
 	}
 
 	public void setRequestAttribute(String key, Object value)
 	{
+		FacesContext context = getFacesContext();
+		if (context != null)
+		{
+			context.getExternalContext().getRequestMap().put(key, value);
+			return;
+		}
+
 		HttpServletRequest request = OrchestraServletFilter.getHttpServletRequest();
 		if (request != null)
 		{
@@ -101,75 +117,93 @@
 			return;
 		}
 
-		FacesContext context = getFacesContext();
-
-		context.getExternalContext().getRequestMap().put(key, value);
+		throw new IllegalStateException(ISE_MESSAGE);
 	}
 
 	public boolean containsRequestAttribute(String key)
 	{
+		FacesContext context = getFacesContext();
+		if (context != null)
+		{
+			return context.getExternalContext().getRequestMap().containsKey(key);
+		}
+
 		HttpServletRequest request = OrchestraServletFilter.getHttpServletRequest();
 		if (request != null)
 		{
 			return request.getAttribute(key) != null;
 		}
 
-		FacesContext context = getFacesContext();
-
-		return context.getExternalContext().getRequestMap().containsKey(key);
+		throw new IllegalStateException(ISE_MESSAGE);
 	}
 
 	public Object getSessionAttribute(String key)
 	{
-		HttpServletRequest request = OrchestraServletFilter.getHttpServletRequest();
-		if (request != null && request.getSession(false) != null)
+		FacesContext context = getFacesContext();
+		if (context != null)
 		{
-			return request.getSession(false).getAttribute(key);
+			return context.getExternalContext().getSessionMap().get(key);
 		}
 
-		FacesContext context = getFacesContext();
+		HttpServletRequest request = OrchestraServletFilter.getHttpServletRequest();
+		if (request != null && request.getSession(true) != null)
+		{
+			return request.getSession(true).getAttribute(key);
+		}
 
-		return context.getExternalContext().getSessionMap().get(key);
+		throw new IllegalStateException(ISE_MESSAGE);
 	}
 
 	public void setSessionAttribute(String key, Object value)
 	{
-		HttpServletRequest request = OrchestraServletFilter.getHttpServletRequest();
-		if (request != null && request.getSession(false) != null)
+		FacesContext context = getFacesContext();
+		if (context != null)
 		{
-			request.getSession(false).setAttribute(key, value);
+			context.getExternalContext().getSessionMap().put(key, value);
 			return;
 		}
 
-		FacesContext context = getFacesContext();
+		HttpServletRequest request = OrchestraServletFilter.getHttpServletRequest();
+		if (request != null && request.getSession(true) != null)
+		{
+			request.getSession(true).setAttribute(key, value);
+			return;
+		}
 
-		context.getExternalContext().getSessionMap().put(key, value);
 	}
 
 	public boolean containsSessionAttribute(String key)
 	{
-		HttpServletRequest request = OrchestraServletFilter.getHttpServletRequest();
-		if (request != null && request.getSession(false) != null)
+		FacesContext context = getFacesContext();
+		if (context != null)
 		{
-			return request.getSession(false).getAttribute(key) != null;
+			return context.getExternalContext().getSessionMap().containsKey(key);
 		}
 
-		FacesContext context = getFacesContext();
+		HttpServletRequest request = OrchestraServletFilter.getHttpServletRequest();
+		if (request != null && request.getSession(true) != null)
+		{
+			return request.getSession(true).getAttribute(key) != null;
+		}
 
-		return context.getExternalContext().getSessionMap().containsKey(key);
+		throw new IllegalStateException(ISE_MESSAGE);
 	}
 
 	public String getRequestContextPath()
 	{
+		FacesContext context = getFacesContext();
+		if (context != null)
+		{
+			return context.getExternalContext().getRequestContextPath();
+		}
+
 		HttpServletRequest request = OrchestraServletFilter.getHttpServletRequest();
-		if (request != null && request.getSession(false) != null)
+		if (request != null)
 		{
 			return request.getContextPath();
 		}
 
-		FacesContext context = getFacesContext();
-
-		return context.getExternalContext().getRequestContextPath();
+		throw new IllegalStateException(ISE_MESSAGE);
 	}
 
 	public ConfigurableApplicationContext getApplicationContext()



Mime
View raw message