[seam-commits] Seam SVN: r12895 - in modules/faces/trunk: impl/src/main/java/org/jboss/seam/faces/context and 3 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Fri May 28 16:39:48 EDT 2010


Author: lincolnthree
Date: 2010-05-28 16:39:48 -0400 (Fri, 28 May 2010)
New Revision: 12895

Added:
   modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/event/PreNavigateEvent.java
   modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/event/PreNavigateEventProducer.java
Modified:
   modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/context/FlashScopedContext.java
   modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/status/MessagesAdapter.java
   modules/faces/trunk/impl/src/main/resources/META-INF/faces-config.xml
Log:
Flash scope and MessagesAdapter are operational.

Added: modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/event/PreNavigateEvent.java
===================================================================
--- modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/event/PreNavigateEvent.java	                        (rev 0)
+++ modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/event/PreNavigateEvent.java	2010-05-28 20:39:48 UTC (rev 12895)
@@ -0,0 +1,74 @@
+/*
+ * 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.event;
+
+import javax.faces.application.NavigationCase;
+import javax.faces.application.NavigationHandler;
+import javax.faces.context.FacesContext;
+
+/**
+ * An event that is fired when JSF navigation is invoked via the
+ * {@link NavigationHandler}, but before any redirecting or non-redirecting
+ * navigation is completed, giving consumers of this event a chance to take
+ * action.
+ * 
+ * @author <a href="mailto:lincolnbaxter at gmail.com>Lincoln Baxter, III</a>
+ * 
+ */
+public class PreNavigateEvent
+{
+
+   private final FacesContext context;
+   private final String fromAction;
+   private final String outcome;
+   private final NavigationCase navigationCase;
+
+   public PreNavigateEvent(final FacesContext context, final String fromAction, final String outcome, final NavigationCase navigationCase)
+   {
+      this.context = context;
+      this.fromAction = fromAction;
+      this.outcome = outcome;
+      this.navigationCase = navigationCase;
+   }
+
+   public FacesContext getContext()
+   {
+      return context;
+   }
+
+   public String getFromAction()
+   {
+      return fromAction;
+   }
+
+   public String getOutcome()
+   {
+      return outcome;
+   }
+
+   public NavigationCase getNavigationCase()
+   {
+      return navigationCase;
+   }
+
+}

Modified: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/context/FlashScopedContext.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/context/FlashScopedContext.java	2010-05-28 16:35:02 UTC (rev 12894)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/context/FlashScopedContext.java	2010-05-28 20:39:48 UTC (rev 12895)
@@ -95,13 +95,14 @@
          String currentId = getCurrentId();
          if (savedContextExists(currentId))
          {
-            FlashContext context = (FlashContext) getSessionMap().remove(getSessionKey(currentId));
+            FlashContext context = (FlashContext) getSessionMap().get(getSessionKey(currentId));
             currentContext = context;
          }
          else
          {
             FlashContextImpl context = new FlashContextImpl();
             context.setId(getNextFlashId());
+            getSessionMap().put(getSessionKey(context.getId()), context);
             currentContext = context;
          }
       }
@@ -144,6 +145,8 @@
    {
       if (PhaseId.RENDER_RESPONSE.equals(event.getPhaseId()))
       {
+         getSessionMap().remove(getSessionKey(currentContext.getId()));
+
          Map<Contextual<?>, Object> componentInstanceMap = getComponentInstanceMap();
          Map<Contextual<?>, CreationalContext<?>> creationalContextMap = getCreationalContextMap();
 

Added: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/event/PreNavigateEventProducer.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/event/PreNavigateEventProducer.java	                        (rev 0)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/event/PreNavigateEventProducer.java	2010-05-28 20:39:48 UTC (rev 12895)
@@ -0,0 +1,69 @@
+/*
+ * 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.event;
+
+import java.util.Map;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.faces.application.ConfigurableNavigationHandler;
+import javax.faces.application.NavigationCase;
+import javax.faces.context.FacesContext;
+
+import org.jboss.weld.extensions.beanManager.BeanManagerAccessor;
+
+/**
+ * @author <a href="mailto:lincolnbaxter at gmail.com>Lincoln Baxter, III</a>
+ * 
+ */
+public class PreNavigateEventProducer extends ConfigurableNavigationHandler
+{
+   private final ConfigurableNavigationHandler parent;
+
+   public PreNavigateEventProducer(final ConfigurableNavigationHandler parent)
+   {
+      this.parent = parent;
+   }
+
+   @Override
+   public NavigationCase getNavigationCase(final FacesContext context, final String fromAction, final String outcome)
+   {
+      return parent.getNavigationCase(context, fromAction, outcome);
+   }
+
+   @Override
+   public Map<String, Set<NavigationCase>> getNavigationCases()
+   {
+      return parent.getNavigationCases();
+   }
+
+   @Override
+   public void handleNavigation(final FacesContext context, final String fromAction, final String outcome)
+   {
+      BeanManager manager = BeanManagerAccessor.getManager();
+      NavigationCase navigationCase = getNavigationCase(context, fromAction, outcome);
+      manager.fireEvent(new PreNavigateEvent(context, fromAction, outcome, navigationCase));
+      parent.handleNavigation(context, fromAction, outcome);
+   }
+
+}

Modified: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/status/MessagesAdapter.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/status/MessagesAdapter.java	2010-05-28 16:35:02 UTC (rev 12894)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/status/MessagesAdapter.java	2010-05-28 20:39:48 UTC (rev 12895)
@@ -23,6 +23,7 @@
 package org.jboss.seam.faces.status;
 
 import java.io.Serializable;
+import java.util.Set;
 
 import javax.enterprise.event.Observes;
 import javax.faces.application.FacesMessage;
@@ -30,6 +31,8 @@
 import javax.faces.event.PhaseEvent;
 import javax.inject.Inject;
 
+import org.jboss.seam.faces.context.FlashContext;
+import org.jboss.seam.faces.event.PreNavigateEvent;
 import org.jboss.seam.faces.event.qualifier.Before;
 import org.jboss.seam.faces.event.qualifier.RenderResponse;
 import org.jboss.seam.international.status.Level;
@@ -47,13 +50,32 @@
 {
    private static final long serialVersionUID = -2908193057765795662L;
 
+   private static final String FLASH_MESSAGES_KEY = MessagesAdapter.class.getName() + ".FLASH_KEY";
+
    @Inject
-   private Messages messages;
+   Messages messages;
 
-   // void flushBeforeNavigate(@Observes BeforeNavigateEvent event);
+   @Inject
+   FlashContext context;
 
+   void flushBeforeNavigate(@Observes final PreNavigateEvent event)
+   {
+      context.put(FLASH_MESSAGES_KEY, messages.getAll());
+      messages.clear();
+   }
+
+   @SuppressWarnings("unchecked")
    void convert(@Observes @Before @RenderResponse final PhaseEvent event)
    {
+      Set<Message> savedMessages = (Set<Message>) context.get(FLASH_MESSAGES_KEY);
+      if (savedMessages != null)
+      {
+         for (Message m : savedMessages)
+         {
+            event.getFacesContext().addMessage(m.getTargets(), new FacesMessage(getSeverity(m.getLevel()), m.getText(), null));
+         }
+      }
+
       for (Message m : messages.getAll())
       {
          event.getFacesContext().addMessage(m.getTargets(), new FacesMessage(getSeverity(m.getLevel()), m.getText(), null));

Modified: modules/faces/trunk/impl/src/main/resources/META-INF/faces-config.xml
===================================================================
--- modules/faces/trunk/impl/src/main/resources/META-INF/faces-config.xml	2010-05-28 16:35:02 UTC (rev 12894)
+++ modules/faces/trunk/impl/src/main/resources/META-INF/faces-config.xml	2010-05-28 20:39:48 UTC (rev 12895)
@@ -10,6 +10,9 @@
 		<after>
 			<name>weld</name>
 		</after>
+		<before>
+			<others/>
+		</before>
 	</ordering>
 
 	<lifecycle>
@@ -21,6 +24,10 @@
 	</factory>
 
 	<application>
+		<navigation-handler>
+			org.jboss.seam.faces.event.PreNavigateEventProducer
+		</navigation-handler>
+		
 		<system-event-listener>
 			<system-event-listener-class>org.jboss.seam.faces.event.DelegatingSystemEventListener</system-event-listener-class>
 			<system-event-class>javax.faces.event.ComponentSystemEvent</system-event-class>



More information about the seam-commits mailing list