[seam-commits] Seam SVN: r12878 - in modules/faces/trunk: impl/src/main/java/org/jboss/seam/faces/environment and 1 other directory.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Thu May 27 21:36:21 EDT 2010


Author: lincolnthree
Date: 2010-05-27 21:36:21 -0400 (Thu, 27 May 2010)
New Revision: 12878

Added:
   modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/context/FlashContext.java
   modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/SeamExternalContext.java
   modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/SeamExternalContextFactory.java
Log:
First stab at real FlashScope implementation #2

Added: modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/context/FlashContext.java
===================================================================
--- modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/context/FlashContext.java	                        (rev 0)
+++ modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/context/FlashContext.java	2010-05-28 01:36:21 UTC (rev 12878)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.seam.faces.context;
+
+/**
+ * A context that lives from Restore View to the next Render Response.
+ * 
+ * @author <a href="mailto:lincolnbaxter at gmail.com>Lincoln Baxter, III</a>
+ * 
+ */
+public interface FlashContext
+{
+
+   /**
+    * Returns true if the current {@link FlashContext} contains no data.
+    */
+   boolean isEmpty();
+
+   /**
+    * Return the current ID of this request's {@link FlashContext}. If the ID
+    * has not yet been set as part of a redirect, the ID will be null.
+    */
+   String getId();
+
+   /**
+    * Get a key value pair from the {@link FlashContext}.
+    */
+   Object get(String key);
+
+   /**
+    * Put a key value pair into the {@link FlashContext}.
+    */
+   void put(String key, Object value);
+
+}

Added: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/SeamExternalContext.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/SeamExternalContext.java	                        (rev 0)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/SeamExternalContext.java	2010-05-28 01:36:21 UTC (rev 12878)
@@ -0,0 +1,51 @@
+package org.jboss.seam.faces.environment;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.enterprise.context.RequestScoped;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.ExternalContextWrapper;
+import javax.inject.Inject;
+
+import org.jboss.seam.faces.context.FlashContext;
+import org.jboss.seam.faces.context.FlashScopedContext;
+
+ at RequestScoped
+public class SeamExternalContext extends ExternalContextWrapper
+{
+   private ExternalContext wrapped;
+
+   @Inject
+   FlashContext flash;
+
+   @Inject
+   FlashScopedContext context;
+
+   public void setWrapped(final ExternalContext wrapped)
+   {
+      this.wrapped = wrapped;
+   }
+
+   @Override
+   public ExternalContext getWrapped()
+   {
+      return wrapped;
+   }
+
+   @Override
+   public String encodeRedirectURL(final String baseUrl, Map<String, List<String>> parameters)
+   {
+      if (!flash.isEmpty())
+      {
+         if (parameters == null)
+         {
+            parameters = new HashMap<String, List<String>>();
+         }
+         parameters.put(context.getRequestParameterName(), Arrays.asList(flash.getId()));
+      }
+      return super.encodeRedirectURL(baseUrl, parameters);
+   }
+}

Added: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/SeamExternalContextFactory.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/SeamExternalContextFactory.java	                        (rev 0)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/SeamExternalContextFactory.java	2010-05-28 01:36:21 UTC (rev 12878)
@@ -0,0 +1,44 @@
+package org.jboss.seam.faces.environment;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.faces.FacesException;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.ExternalContextFactory;
+
+import org.jboss.seam.faces.util.BeanManagerUtils;
+import org.jboss.weld.extensions.beanManager.BeanManagerAccessor;
+
+public class SeamExternalContextFactory extends ExternalContextFactory
+{
+   private final ExternalContextFactory parent;
+
+   public SeamExternalContextFactory(final ExternalContextFactory parent)
+   {
+      super();
+      this.parent = parent;
+   }
+
+   @Override
+   public ExternalContext getExternalContext(final Object context, final Object request, final Object response) throws FacesException
+   {
+      try
+      {
+         BeanManager manager = BeanManagerAccessor.getManager();
+
+         SeamExternalContext seamExternalContext = BeanManagerUtils.getContextualInstance(manager, SeamExternalContext.class);
+         seamExternalContext.setWrapped(parent.getExternalContext(context, request, response));
+
+         return seamExternalContext;
+      }
+      catch (Exception e)
+      {
+         throw new IllegalStateException("Could not wrap ExternalContext", e);
+      }
+   }
+
+   @Override
+   public ExternalContextFactory getWrapped()
+   {
+      return parent;
+   }
+}



More information about the seam-commits mailing list