You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by ni...@apache.org on 2005/11/09 05:51:01 UTC

svn commit: r331950 - in /struts/taglib/trunk/src/java/org/apache/struts/taglib/html: LocalStrings.properties MessagesTag.java

Author: niallp
Date: Tue Nov  8 20:50:53 2005
New Revision: 331950

URL: http://svn.apache.org/viewcvs?rev=331950&view=rev
Log:
Refactor message processing into common method and display an error message if a resource key is not found (rather than removing the page scope attribute).

Modified:
    struts/taglib/trunk/src/java/org/apache/struts/taglib/html/LocalStrings.properties
    struts/taglib/trunk/src/java/org/apache/struts/taglib/html/MessagesTag.java

Modified: struts/taglib/trunk/src/java/org/apache/struts/taglib/html/LocalStrings.properties
URL: http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/LocalStrings.properties?rev=331950&r1=331949&r2=331950&view=diff
==============================================================================
--- struts/taglib/trunk/src/java/org/apache/struts/taglib/html/LocalStrings.properties (original)
+++ struts/taglib/trunk/src/java/org/apache/struts/taglib/html/LocalStrings.properties Tue Nov  8 20:50:53 2005
@@ -34,6 +34,7 @@
 linkTag.type1=Object must be of type Dictionary
 linkTag.url=Cannot create link URL: {0}
 messageTag.resources=Missing resources attribute {0}
+messagesTag.notfound=ERROR: Resource key \"{0}\" not found in {1} bundle
 multiboxTag.value=You must specify the value attribute or nested tag content
 optionsCollectionTag.collection=Failed to obtain specified collection
 optionsCollectionTag.iterator=Cannot create iterator for {0}

Modified: struts/taglib/trunk/src/java/org/apache/struts/taglib/html/MessagesTag.java
URL: http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/MessagesTag.java?rev=331950&r1=331949&r2=331950&view=diff
==============================================================================
--- struts/taglib/trunk/src/java/org/apache/struts/taglib/html/MessagesTag.java (original)
+++ struts/taglib/trunk/src/java/org/apache/struts/taglib/html/MessagesTag.java Tue Nov  8 20:50:53 2005
@@ -1,7 +1,7 @@
 /*
  * $Id$ 
  *
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -200,24 +200,8 @@
             return SKIP_BODY;
         }
 
-        ActionMessage report = (ActionMessage) this.iterator.next();
-        String msg = null;
-        if (report.isResource()) {
-            msg = TagUtils.getInstance().message(
-                     pageContext,
-                     bundle,
-                     locale,
-                     report.getKey(),
-                     report.getValues());
-        } else {
-            msg = report.getKey();
-        }
-
-        if (msg == null) {
-            pageContext.removeAttribute(id);
-        } else {
-            pageContext.setAttribute(id, msg);
-        }
+        // process the first message
+        processMessage((ActionMessage)iterator.next());
 
         if (header != null && header.length() > 0) {
             String headerMessage =
@@ -250,32 +234,43 @@
 
         // Decide whether to iterate or quit
         if (iterator.hasNext()) {
-            ActionMessage report = (ActionMessage) iterator.next();
-            String msg = null;
-            if (report.isResource()) {
-                msg = TagUtils.getInstance().message(
+            processMessage((ActionMessage)iterator.next());
+           return (EVAL_BODY_TAG);
+        } else {
+           return (SKIP_BODY);
+        }
+
+    }
+
+    /**
+     * Process a message.
+     */
+    private void processMessage(ActionMessage report) throws JspException  {
+
+        String msg = null;
+        if (report.isResource()) {
+            msg = TagUtils.getInstance().message(
                     pageContext,
                     bundle,
                     locale,
                     report.getKey(),
                     report.getValues());
-            } else {
-                msg = report.getKey();
+            if (msg == null) {
+                String bundleName = bundle == null ? "default" : bundle;
+                msg = messageResources.getMessage("messagesTag.notfound", 
+                       report.getKey(), bundleName);
             }
-
-           if (msg == null) {
-               pageContext.removeAttribute(id);
-           } else {
-               pageContext.setAttribute(id, msg);
-           }
-
-           return (EVAL_BODY_TAG);
         } else {
-           return (SKIP_BODY);
+            msg = report.getKey();
         }
 
-    }
+       if (msg == null) {
+           pageContext.removeAttribute(id);
+       } else {
+           pageContext.setAttribute(id, msg);
+       }
 
+    }
 
     /**
      * Clean up after processing this enumeration.



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