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

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Thu Apr 30 16:56:30 EDT 2009


Author: dan.j.allen
Date: 2009-04-30 16:56:30 -0400 (Thu, 30 Apr 2009)
New Revision: 10735

Added:
   modules/trunk/faces/src/main/java/org/jboss/seam/faces/application/SeamViewHandler.java
Modified:
   modules/trunk/faces/src/main/java/org/jboss/seam/faces/FacesStatusMessages.java
   modules/trunk/faces/src/main/java/org/jboss/seam/faces/lifecycle/TransferStatusMessagesListener.java
   modules/trunk/faces/src/main/resources/META-INF/faces-config.xml
   modules/trunk/international/src/main/java/org/jboss/seam/international/StatusMessages.java
Log:
preserve messages on a redirect
change default severity to WARN for addToControl


Modified: modules/trunk/faces/src/main/java/org/jboss/seam/faces/FacesStatusMessages.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/FacesStatusMessages.java	2009-04-30 20:26:53 UTC (rev 10734)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/FacesStatusMessages.java	2009-04-30 20:56:30 UTC (rev 10735)
@@ -140,6 +140,9 @@
       }
    }
 
+   /**
+    * FIXME does not work if element is inside of form with prependId="false"
+    */
    private boolean isAbsoluteClientIdPresent(String targetId, FacesContext facesContext)
    {
       return facesContext.getViewRoot().findComponent(targetId) != null;

Added: modules/trunk/faces/src/main/java/org/jboss/seam/faces/application/SeamViewHandler.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/application/SeamViewHandler.java	                        (rev 0)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/application/SeamViewHandler.java	2009-04-30 20:56:30 UTC (rev 10735)
@@ -0,0 +1,53 @@
+package org.jboss.seam.faces.application;
+
+import java.util.List;
+import java.util.Map;
+import javax.faces.application.ViewHandler;
+import javax.faces.application.ViewHandlerWrapper;
+import javax.faces.context.FacesContext;
+import org.jboss.seam.faces.lifecycle.TransferStatusMessagesListener;
+import org.jboss.seam.international.StatusMessages;
+
+/**
+ * Wrap the standard JSF view handler to capture the
+ * request for a redirect URL so that the JSF messages
+ * can be preserved.
+ *
+ * @author Dan Allen
+ */
+public class SeamViewHandler extends ViewHandlerWrapper
+{
+   private ViewHandler delegate;
+   
+   public SeamViewHandler(ViewHandler delegate)
+   {
+      this.delegate = delegate;
+   }
+
+   @Override
+   public ViewHandler getWrapped()
+   {
+      return delegate;
+   }
+
+   /**
+    * If JSF is requesting a redirect URL, then likely a redirect is about to be performed.
+    * Take this opportunity to store the JSF messages in the flash scope so that they
+    * live past the redirect.
+    *
+    * @see ViewHandler#getRedirectURL(javax.faces.context.FacesContext, java.lang.String, java.util.Map, boolean) 
+    */
+   @Override
+   public String getRedirectURL(FacesContext context, String viewId, Map<String, List<String>> parameters, boolean includeViewParams)
+   {
+      // QUESTION hmmm, we have to convert to faces messages now to leverage JSF's flash feature...I suppose that is okay
+      new TransferStatusMessagesListener().execute();
+      if (context.getMessages().hasNext())
+      {
+         context.getExternalContext().getFlash().setKeepMessages(true);
+      }
+      
+      return super.getRedirectURL(context, viewId, parameters, includeViewParams);
+   }
+
+}

Modified: modules/trunk/faces/src/main/java/org/jboss/seam/faces/lifecycle/TransferStatusMessagesListener.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/lifecycle/TransferStatusMessagesListener.java	2009-04-30 20:26:53 UTC (rev 10734)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/lifecycle/TransferStatusMessagesListener.java	2009-04-30 20:56:30 UTC (rev 10735)
@@ -10,12 +10,10 @@
 import org.jboss.webbeans.log.Logging;
 
 /**
- * A {@link SystemEventListener} that observes the PreRenderViewEvent and
- * transposes Seam StatusMessage objects into FacesMessage objects
- * and transfers them to the FacesContext.
+ * A {@link SystemEventListener} that observes the PreRenderViewEvent or
+ * a redirect navigation event (via SeamViewHandler) and transposes Seam
+ * StatusMessage objects into FacesMessage objects and transfers them to the FacesContext.
  *
- * FIXME currently losing messages over a redirect after conversation ends (and perhaps when no conversation present)
- *
  * @author Dan Allen
  */
 //@ListenerFor(systemEventClass = PreRenderViewEvent.class, sourceClass = UIViewRoot.class)
@@ -25,6 +23,16 @@
 
    public void processEvent(SystemEvent preRenderViewEvent)
    {
+      execute();
+   }
+
+   public boolean isListenerForSource(Object source)
+   {
+      return true;
+   }
+
+   public void execute()
+   {
       Expressions expressions = new FacesExpressions();
       // FIXME this is kind of ugly...reminds me of the bad old days of JSF managed beans
       StatusMessages statusMessages = (StatusMessages) expressions.createValueExpression(getBeanExpression(StatusMessages.class)).getValue();
@@ -38,11 +46,6 @@
       }
    }
 
-   public boolean isListenerForSource(Object source)
-   {
-      return true;
-   }
-
    private String getBeanName(Class beanClass)
    {
       return beanClass.getPackage().getName() + "." + Introspector.decapitalize(beanClass.getSimpleName());

Modified: modules/trunk/faces/src/main/resources/META-INF/faces-config.xml
===================================================================
--- modules/trunk/faces/src/main/resources/META-INF/faces-config.xml	2009-04-30 20:26:53 UTC (rev 10734)
+++ modules/trunk/faces/src/main/resources/META-INF/faces-config.xml	2009-04-30 20:56:30 UTC (rev 10735)
@@ -14,6 +14,7 @@
    </factory>
 
    <application>
+      <view-handler>org.jboss.seam.faces.application.SeamViewHandler</view-handler>
       <el-resolver>org.jboss.seam.el.SeamELResolver</el-resolver>
       <el-resolver>org.jboss.seam.faces.el.SeamFacesELResolver</el-resolver>
       <system-event-listener>

Modified: modules/trunk/international/src/main/java/org/jboss/seam/international/StatusMessages.java
===================================================================
--- modules/trunk/international/src/main/java/org/jboss/seam/international/StatusMessages.java	2009-04-30 20:26:53 UTC (rev 10734)
+++ modules/trunk/international/src/main/java/org/jboss/seam/international/StatusMessages.java	2009-04-30 20:56:30 UTC (rev 10735)
@@ -46,12 +46,15 @@
  * JSF, Wicket).</p>
  *
  * <p>A status message can either be global or it can be keyed to a "client id", which
- * is the id of a cooresponding user interface component on the page.</p>
+ * is the id of a cooresponding user interface component on the page. The default
+ * severity of a global message is INFO, whereas the default severity of a message
+ * added to a control is WARN. These defaults are choosen since they represent the
+ * most common usage scenario.</p>
  *
  * <p>Seam will interpolate value expressions and positional parameters in
  * message templates. Interpolation is deferred until just before the next view
  * in the conversation is rendered, allowing value expressions to resolve to
- * the final state of the action as with the rest of the view.</p>
+ * the final state of the action as does the rest of the view.</p>
  * 
  * @author Pete Muir
  * @author Dan Allen
@@ -224,13 +227,13 @@
     * used determine which widget the id refers to is determined by the view 
     * layer implementation in use.
     * 
-    * A severity of INFO will be used, and you can specify parameters to be 
+    * A severity of WARN will be used, and you can specify parameters to be
     * interpolated
     * 
     */
    public void addToControl(String id, String messageTemplate, Object... params)
    {
-      addToControl(id, INFO, null, messageTemplate, params);
+      addToControl(id, WARN, null, messageTemplate, params);
    }
 
    /**
@@ -308,13 +311,13 @@
     * used determine which widget the id refers to is determined by the view 
     * layer implementation in use.
     * 
-    * A severity of INFO will be used, and you can specify parameters to be 
+    * A severity of WARN will be used, and you can specify parameters to be
     * interpolated
     * 
     */
    public void addToControlFromResourceBundle(String id, String key, Object... params)
    {
-      addToControlFromResourceBundle(id, INFO, key, params);
+      addToControlFromResourceBundle(id, WARN, key, params);
    }
 
    /**
@@ -342,13 +345,13 @@
     * used determine which widget the id refers to is determined by the view 
     * layer implementation in use.
     * 
-    * A severity of INFO will be used, and you can specify parameters to be 
+    * A severity of WARN will be used, and you can specify parameters to be
     * interpolated
     * 
     */
    public void addToControlFromResourceBundleOrDefault(String id, String key, String defaultMessageTemplate, Object... params)
    {
-      addToControlFromResourceBundleOrDefault(id, INFO, key, defaultMessageTemplate, params);
+      addToControlFromResourceBundleOrDefault(id, WARN, key, defaultMessageTemplate, params);
    }
 
    /**




More information about the seam-commits mailing list