You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by nb...@apache.org on 2005/10/15 02:59:35 UTC

svn commit: r321270 - /jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/struts/StrutsUtils.java

Author: nbubna
Date: Fri Oct 14 17:59:32 2005
New Revision: 321270

URL: http://svn.apache.org/viewcvs?rev=321270&view=rev
Log:
only check for messages in session if there are none in the request to mimic what the struts tags do, and also do the same with errors (thx to Niall Pemberton)

Modified:
    jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/struts/StrutsUtils.java

Modified: jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/struts/StrutsUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/struts/StrutsUtils.java?rev=321270&r1=321269&r2=321270&view=diff
==============================================================================
--- jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/struts/StrutsUtils.java (original)
+++ jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/struts/StrutsUtils.java Fri Oct 14 17:59:32 2005
@@ -182,40 +182,48 @@
 
     /**
      * Returns the Struts errors for this request or <code>null</code>
-     * if none exist.
+     * if none exist. Since VelocityTools 1.2, this will also check
+     * the session (if there is one) for errors if there are no errors
+     * in the request.
      *
      * @param request the servlet request
      * @since VelocityTools 1.1
      */
     public static ActionMessages getErrors(HttpServletRequest request)
     {
-        return (ActionMessages)request.getAttribute(Globals.ERROR_KEY);
+        ActionMessages errors = (ActionMessages)request.getAttribute(Globals.ERROR_KEY);
+        if (errors == null || errors.isEmpty())
+        {
+            // then check the session
+            HttpSession session = request.getSession(false);
+            if (session != null)
+            {
+                errors = (ActionMessages)session.getAttribute(Globals.ERROR_KEY);
+            }
+        }
+        return errors;
     }
 
     /**
      * Returns the Struts messages for this request or <code>null</code>
      * if none exist.  Since VelocityTools 1.2, this will also check
-     * the session for messages (if there is a session).
+     * the session (if there is one) for messages if there are no messages
+     * in the request.
      *
      * @param request the servlet request
      * @since VelocityTools 1.1
      */
     public static ActionMessages getMessages(HttpServletRequest request)
     {
-        ActionMessages messages = new ActionMessages();
-        HttpSession session = request.getSession(false);
-        if (session != null)
+        ActionMessages messages = (ActionMessages)request.getAttribute(Globals.MESSAGE_KEY);
+        if (messages == null || messages.isEmpty())
         {
-            ActionMessages sessionMessages = 
-                (ActionMessages)session.getAttribute(Globals.MESSAGE_KEY);
-            if (sessionMessages != null) {
-                messages.add(sessionMessages);
+            // then check the session
+            HttpSession session = request.getSession(false);
+            if (session != null)
+            {
+                messages = (ActionMessages)session.getAttribute(Globals.MESSAGE_KEY);
             }
-        }
-        ActionMessages requestMessages = 
-            (ActionMessages)request.getAttribute(Globals.MESSAGE_KEY);
-        if (requestMessages != null) {
-            messages.add(requestMessages);
         }
         return messages;
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org