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/03/28 22:19:31 UTC

svn commit: r159291 - in struts/core/branches/STRUTS_1_2_BRANCH: conf/share/ doc/userGuide/ src/share/org/apache/struts/action/ src/share/org/apache/struts/taglib/ src/share/org/apache/struts/taglib/html/ src/share/org/apache/struts/validator/ src/share/org/apache/struts/validator/validwhen/

Author: niallp
Date: Mon Mar 28 12:19:29 2005
New Revision: 159291

URL: http://svn.apache.org/viewcvs?view=rev&rev=159291
Log:
Port changes for Bugzilla #21760 to 1.2.X Branch

Modified:
    struts/core/branches/STRUTS_1_2_BRANCH/conf/share/validator-rules.xml
    struts/core/branches/STRUTS_1_2_BRANCH/doc/userGuide/struts-html.xml
    struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/action/ActionMessage.java
    struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/taglib/TagUtils.java
    struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/taglib/html/ErrorsTag.java
    struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/taglib/html/JavascriptValidatorTag.java
    struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/taglib/html/MessagesTag.java
    struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/validator/FieldChecks.java
    struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/validator/Resources.java
    struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/validator/validwhen/ValidWhen.java

Modified: struts/core/branches/STRUTS_1_2_BRANCH/conf/share/validator-rules.xml
URL: http://svn.apache.org/viewcvs/struts/core/branches/STRUTS_1_2_BRANCH/conf/share/validator-rules.xml?view=diff&r1=159290&r2=159291
==============================================================================
--- struts/core/branches/STRUTS_1_2_BRANCH/conf/share/validator-rules.xml (original)
+++ struts/core/branches/STRUTS_1_2_BRANCH/conf/share/validator-rules.xml Mon Mar 28 12:19:29 2005
@@ -56,6 +56,7 @@
                        org.apache.commons.validator.ValidatorAction,
                        org.apache.commons.validator.Field,
                        org.apache.struts.action.ActionMessages,
+                       org.apache.commons.validator.Validator,
                        javax.servlet.http.HttpServletRequest"
                   msg="errors.required"/>
 
@@ -89,6 +90,7 @@
                        org.apache.commons.validator.ValidatorAction,
                        org.apache.commons.validator.Field,
                        org.apache.struts.action.ActionMessages,
+                       org.apache.commons.validator.Validator,
                        javax.servlet.http.HttpServletRequest"
               depends=""
                   msg="errors.minlength"
@@ -102,6 +104,7 @@
                        org.apache.commons.validator.ValidatorAction,
                        org.apache.commons.validator.Field,
                        org.apache.struts.action.ActionMessages,
+                       org.apache.commons.validator.Validator,
                        javax.servlet.http.HttpServletRequest"
               depends=""
                   msg="errors.maxlength"
@@ -116,6 +119,7 @@
                        org.apache.commons.validator.ValidatorAction,
                        org.apache.commons.validator.Field,
                        org.apache.struts.action.ActionMessages,
+                       org.apache.commons.validator.Validator,
                        javax.servlet.http.HttpServletRequest"
               depends=""
                   msg="errors.invalid"/>
@@ -128,6 +132,7 @@
                        org.apache.commons.validator.ValidatorAction,
                        org.apache.commons.validator.Field,
                        org.apache.struts.action.ActionMessages,
+                       org.apache.commons.validator.Validator,
                        javax.servlet.http.HttpServletRequest"
               depends=""
                   msg="errors.byte"
@@ -141,6 +146,7 @@
                        org.apache.commons.validator.ValidatorAction,
                        org.apache.commons.validator.Field,
                        org.apache.struts.action.ActionMessages,
+                       org.apache.commons.validator.Validator,
                        javax.servlet.http.HttpServletRequest"
               depends=""
                   msg="errors.short"
@@ -154,6 +160,7 @@
                        org.apache.commons.validator.ValidatorAction,
                        org.apache.commons.validator.Field,
                        org.apache.struts.action.ActionMessages,
+                       org.apache.commons.validator.Validator,
                        javax.servlet.http.HttpServletRequest"
               depends=""
                   msg="errors.integer"
@@ -168,6 +175,7 @@
                        org.apache.commons.validator.ValidatorAction,
                        org.apache.commons.validator.Field,
                        org.apache.struts.action.ActionMessages,
+                       org.apache.commons.validator.Validator,
                        javax.servlet.http.HttpServletRequest"
               depends=""
                   msg="errors.long"/>
@@ -180,6 +188,7 @@
                        org.apache.commons.validator.ValidatorAction,
                        org.apache.commons.validator.Field,
                        org.apache.struts.action.ActionMessages,
+                       org.apache.commons.validator.Validator,
                        javax.servlet.http.HttpServletRequest"
               depends=""
                   msg="errors.float"
@@ -192,6 +201,7 @@
                        org.apache.commons.validator.ValidatorAction,
                        org.apache.commons.validator.Field,
                        org.apache.struts.action.ActionMessages,
+                       org.apache.commons.validator.Validator,
                        javax.servlet.http.HttpServletRequest"
               depends=""
                   msg="errors.double"/>
@@ -204,6 +214,7 @@
                        org.apache.commons.validator.ValidatorAction,
                        org.apache.commons.validator.Field,
                        org.apache.struts.action.ActionMessages,
+                       org.apache.commons.validator.Validator,
                        javax.servlet.http.HttpServletRequest"
               depends=""
                   msg="errors.date"
@@ -217,6 +228,7 @@
                        org.apache.commons.validator.ValidatorAction,
                        org.apache.commons.validator.Field,
                        org.apache.struts.action.ActionMessages,
+                       org.apache.commons.validator.Validator,
                        javax.servlet.http.HttpServletRequest"
               depends="integer"
                   msg="errors.range"/>
@@ -229,6 +241,7 @@
                        org.apache.commons.validator.ValidatorAction,
                        org.apache.commons.validator.Field,
                        org.apache.struts.action.ActionMessages,
+                       org.apache.commons.validator.Validator,
                        javax.servlet.http.HttpServletRequest"
               depends="float"
                   msg="errors.range"/>
@@ -240,6 +253,7 @@
                        org.apache.commons.validator.ValidatorAction,
                        org.apache.commons.validator.Field,
                        org.apache.struts.action.ActionMessages,
+                       org.apache.commons.validator.Validator,
                        javax.servlet.http.HttpServletRequest"
               depends="double"
                   msg="errors.range"/>
@@ -252,6 +266,7 @@
                        org.apache.commons.validator.ValidatorAction,
                        org.apache.commons.validator.Field,
                        org.apache.struts.action.ActionMessages,
+                       org.apache.commons.validator.Validator,
                        javax.servlet.http.HttpServletRequest"
               depends=""
                   msg="errors.creditcard"/>
@@ -264,6 +279,7 @@
                        org.apache.commons.validator.ValidatorAction,
                        org.apache.commons.validator.Field,
                        org.apache.struts.action.ActionMessages,
+                       org.apache.commons.validator.Validator,
                        javax.servlet.http.HttpServletRequest"
               depends=""
                   msg="errors.email"/>
@@ -275,6 +291,7 @@
                        org.apache.commons.validator.ValidatorAction,
                        org.apache.commons.validator.Field,
                        org.apache.struts.action.ActionMessages,
+                       org.apache.commons.validator.Validator,
                        javax.servlet.http.HttpServletRequest"
               depends=""
                   msg="errors.url"/>

Modified: struts/core/branches/STRUTS_1_2_BRANCH/doc/userGuide/struts-html.xml
URL: http://svn.apache.org/viewcvs/struts/core/branches/STRUTS_1_2_BRANCH/doc/userGuide/struts-html.xml?view=diff&r1=159290&r2=159291
==============================================================================
--- struts/core/branches/STRUTS_1_2_BRANCH/doc/userGuide/struts-html.xml (original)
+++ struts/core/branches/STRUTS_1_2_BRANCH/doc/userGuide/struts-html.xml Mon Mar 28 12:19:29 2005
@@ -3681,6 +3681,17 @@
                </p>
             </info>
         </attribute>
+        <attribute>
+                <name>bundle</name>
+                <required>false</required>
+                <rtexprvalue>true</rtexprvalue>
+                <info>
+                    The servlet context attributes key for the MessageResources
+                    instance to use.  If not specified, defaults to the
+                    application resources configured for our action servlet.
+                </info>
+                <since>Struts 1.2.7</since>
+        </attribute>
 
     </tag>
 

Modified: struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/action/ActionMessage.java
URL: http://svn.apache.org/viewcvs/struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/action/ActionMessage.java?view=diff&r1=159290&r2=159291
==============================================================================
--- struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/action/ActionMessage.java (original)
+++ struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/action/ActionMessage.java Mon Mar 28 12:19:29 2005
@@ -110,6 +110,20 @@
 
         this.key = key;
         this.values = values;
+        this.resource = true;
+
+    }
+
+    /**
+     * <p>Construct an action message with the specified replacement values.</p>
+     *
+     * @param key Message key for this message
+     * @param resource Indicates whether the key is a bundle key or literal value
+     */
+    public ActionMessage(String key, boolean resource) {
+ 
+        this.key = key;
+        this.resource = resource;
 
     }
 
@@ -128,6 +142,11 @@
      */
     protected Object values[] = null;
 
+    /**
+     * <p>Indicates whether the key is taken to be as a  bundle key [true] or literal value [false].</p>
+     */
+    protected boolean resource = true;
+
 
     // --------------------------------------------------------- Public Methods
 
@@ -148,6 +167,16 @@
     public Object[] getValues() {
 
         return (this.values);
+
+    }
+
+
+    /**
+     * <p>Indicate whether the key is taken to be as a  bundle key [true] or literal value [false].</p>
+     */
+    public boolean isResource() {
+
+        return (this.resource);
 
     }
     

Modified: struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/taglib/TagUtils.java
URL: http://svn.apache.org/viewcvs/struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/taglib/TagUtils.java?view=diff&r1=159290&r2=159291
==============================================================================
--- struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/taglib/TagUtils.java (original)
+++ struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/taglib/TagUtils.java Mon Mar 28 12:19:29 2005
@@ -1207,7 +1207,7 @@
      * @return MessageResources The bundle's resources stored in some scope.
      * @throws JspException if the MessageResources object could not be found.
      */
-    private MessageResources retrieveMessageResources(
+    public MessageResources retrieveMessageResources(
             PageContext pageContext,
             String bundle,
             boolean checkPageScope)

Modified: struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/taglib/html/ErrorsTag.java
URL: http://svn.apache.org/viewcvs/struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/taglib/html/ErrorsTag.java?view=diff&r1=159290&r2=159291
==============================================================================
--- struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/taglib/html/ErrorsTag.java (original)
+++ struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/taglib/html/ErrorsTag.java Mon Mar 28 12:19:29 2005
@@ -245,13 +245,17 @@
                 results.append(message);
             }
             
-            message =
-                TagUtils.getInstance().message(
-                    pageContext,
-                    bundle,
-                    locale,
-                    report.getKey(),
-                    report.getValues());
+            if (report.isResource()) {
+                message =
+                    TagUtils.getInstance().message(
+                        pageContext,
+                        bundle,
+                        locale,
+                        report.getKey(),
+                        report.getValues());
+            } else {
+                message = report.getKey();
+            }
                     
             if (message != null) {
                 results.append(message);

Modified: struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/taglib/html/JavascriptValidatorTag.java
URL: http://svn.apache.org/viewcvs/struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/taglib/html/JavascriptValidatorTag.java?view=diff&r1=159290&r2=159291
==============================================================================
--- struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/taglib/html/JavascriptValidatorTag.java (original)
+++ struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/taglib/html/JavascriptValidatorTag.java Mon Mar 28 12:19:29 2005
@@ -27,12 +27,15 @@
 import java.util.Locale;
 import java.util.Map;
 
+import javax.servlet.ServletContext;
 import javax.servlet.jsp.JspException;
 import javax.servlet.jsp.JspWriter;
 import javax.servlet.jsp.PageContext;
 import javax.servlet.jsp.tagext.BodyTagSupport;
+import javax.servlet.http.HttpServletRequest;
 
 import org.apache.commons.validator.Field;
+import org.apache.commons.validator.Msg;
 import org.apache.commons.validator.Form;
 import org.apache.commons.validator.ValidatorAction;
 import org.apache.commons.validator.ValidatorResources;
@@ -322,6 +325,20 @@
     }
 
     /**
+     * Sets the servlet context attribute key for our resources.
+     */
+    public String getBundle() {
+        return bundle;
+    }
+
+    /**
+     * Gets the servlet context attribute key for our resources.
+     */
+    public void setBundle(String bundle) {
+        this.bundle = bundle;
+    }
+
+    /**
      * Render the JavaScript for to perform validations based on the form name.
      *
      * @exception JspException if a JSP exception has occurred
@@ -408,10 +425,11 @@
 
         StringBuffer results = new StringBuffer();
 
-        MessageResources messages =
-            (MessageResources) pageContext.getAttribute(
-                bundle + config.getPrefix(),
-                PageContext.APPLICATION_SCOPE);
+        MessageResources messages = 
+            TagUtils.getInstance().retrieveMessageResources(pageContext, bundle, true);
+ 
+        HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
+        ServletContext application = pageContext.getServletContext();
 
         List actions = this.createActionList(resources, form);
 
@@ -459,7 +477,12 @@
                     continue;
                 }
 
-                String message = Resources.getMessage(messages, locale, va, field);
+                String message =  Resources.getMessage(application,
+                                                       request,
+                                                       messages,
+                                                       locale,
+                                                       va,
+                                                       field);
 
                 message = (message != null) ? message : "";
 

Modified: struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/taglib/html/MessagesTag.java
URL: http://svn.apache.org/viewcvs/struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/taglib/html/MessagesTag.java?view=diff&r1=159290&r2=159291
==============================================================================
--- struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/taglib/html/MessagesTag.java (original)
+++ struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/taglib/html/MessagesTag.java Mon Mar 28 12:19:29 2005
@@ -201,13 +201,17 @@
         }
 
         ActionMessage report = (ActionMessage) this.iterator.next();
-        String msg =
-            TagUtils.getInstance().message(
-                pageContext,
-                bundle,
-                locale,
-                report.getKey(),
-                report.getValues());
+        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);

Modified: struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/validator/FieldChecks.java
URL: http://svn.apache.org/viewcvs/struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/validator/FieldChecks.java?view=diff&r1=159290&r2=159291
==============================================================================
--- struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/validator/FieldChecks.java (original)
+++ struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/validator/FieldChecks.java Mon Mar 28 12:19:29 2005
@@ -23,6 +23,7 @@
 import java.util.Locale;
 import java.util.StringTokenizer;
 
+import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.commons.logging.Log;
@@ -31,6 +32,7 @@
 import org.apache.commons.validator.GenericTypeValidator;
 import org.apache.commons.validator.GenericValidator;
 import org.apache.commons.validator.UrlValidator;
+import org.apache.commons.validator.Validator;
 import org.apache.commons.validator.ValidatorAction;
 import org.apache.commons.validator.util.ValidatorUtils;
 import org.apache.struts.action.ActionMessages;
@@ -70,12 +72,15 @@
      * field being validated.
      * @param errors The <code>ActionMessages</code> object to add errors to if
      * any validation errors occur.
+     * @param validator The <code>Validator</code> instance, used to access
+     *                  other field values.
      * @param request Current request object.
      * @return true if meets stated requirements, false otherwise.
      */
     public static boolean validateRequired(Object bean,
                                            ValidatorAction va, Field field,
                                            ActionMessages errors,
+                                           Validator validator,
                                            HttpServletRequest request) {
 
         String value = null;
@@ -86,7 +91,7 @@
         }
 
         if (GenericValidator.isBlankOrNull(value)) {
-            errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
+            errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
             return false;
         } else {
             return true;
@@ -112,7 +117,7 @@
     public static boolean validateRequiredIf(Object bean,
                                              ValidatorAction va, Field field,
                                              ActionMessages errors,
-                                             org.apache.commons.validator.Validator validator,
+                                             Validator validator,
                                              HttpServletRequest request) {
 
         Object form = validator.getParameterValue(org.apache.commons.validator.Validator.BEAN_PARAM);
@@ -189,7 +194,7 @@
 			if (GenericValidator.isBlankOrNull(value)) {
 				errors.add(
 					field.getKey(),
-					Resources.getActionMessage(request, va, field));
+					Resources.getActionMessage(validator, request, va, field));
 
                 return false;
 
@@ -210,12 +215,15 @@
      * field being validated.
      * @param errors   The <code>ActionMessages</code> object to add errors to if
      * any validation errors occur.
+     * @param validator The <code>Validator</code> instance, used to access
+     * other field values.
      * @param request Current request object.
      * @return true if field matches mask, false otherwise.
      */
     public static boolean validateMask(Object bean,
                                        ValidatorAction va, Field field,
                                        ActionMessages errors,
+                                       Validator validator,
                                        HttpServletRequest request) {
 
         String mask = field.getVarValue("mask");
@@ -232,7 +240,7 @@
 
                 errors.add(
                     field.getKey(),
-                    Resources.getActionMessage(request, va, field));
+                    Resources.getActionMessage(validator, request, va, field));
 
                 return false;
             } else {
@@ -254,12 +262,15 @@
      *field being validated.
      *@param errors The <code>ActionMessages</code> object to add errors to if
      *any validation errors occur.
+     * @param validator The <code>Validator</code> instance, used to access
+     * other field values.
      *@param request Current request object.
      *@return true if valid, false otherwise.
      */
     public static Object validateByte(Object bean,
                                     ValidatorAction va, Field field,
                                     ActionMessages errors,
+                                    Validator validator,
                                     HttpServletRequest request) {
 
         Object result = null;
@@ -277,7 +288,7 @@
         result = GenericTypeValidator.formatByte(value);
 
         if (result == null) {
-            errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
+            errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
         }
 
         return result == null ? Boolean.FALSE : result;
@@ -293,12 +304,15 @@
      * field being validated.
      * @param errors The <code>ActionMessages</code> object to add errors to if
      * any validation errors occur.
+     * @param validator The <code>Validator</code> instance, used to access
+     * other field values.
      * @param request Current request object.
      * @return true if valid, false otherwise.
      */
     public static Object validateShort(Object bean,
                                       ValidatorAction va, Field field,
                                       ActionMessages errors,
+                                      Validator validator,
                                       HttpServletRequest request) {
         Object result = null;
         String value = null;
@@ -315,7 +329,7 @@
         result = GenericTypeValidator.formatShort(value);
 
         if (result == null) {
-            errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
+            errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
         }
 
         return result == null ? Boolean.FALSE : result;
@@ -331,12 +345,15 @@
      *      field being validated.
      * @param  errors   The <code>ActionMessages</code> object to add errors to if any
      *      validation errors occur.
+     * @param validator The <code>Validator</code> instance, used to access
+     * other field values.
      * @param  request  Current request object.
      * @return true if valid, false otherwise.
      */
     public static Object validateInteger(Object bean,
                                           ValidatorAction va, Field field,
                                           ActionMessages errors,
+                                          Validator validator,
                                           HttpServletRequest request) {
         Object result = null;
         String value = null;
@@ -353,7 +370,7 @@
         result = GenericTypeValidator.formatInt(value);
 
         if (result == null) {
-            errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
+            errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
         }
 
         return result == null ? Boolean.FALSE : result;
@@ -369,12 +386,15 @@
      *      field being validated.
      * @param  errors   The <code>ActionMessages</code> object to add errors to if any
      *      validation errors occur.
+     * @param validator The <code>Validator</code> instance, used to access
+     * other field values.
      * @param  request  Current request object.
      * @return true if valid, false otherwise.
      */
     public static Object validateLong(Object bean,
                                     ValidatorAction va, Field field,
                                     ActionMessages errors,
+                                    Validator validator,
                                     HttpServletRequest request) {
         Object result = null;
         String value = null;
@@ -391,7 +411,7 @@
         result = GenericTypeValidator.formatLong(value);
 
         if (result == null) {
-            errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
+            errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
         }
 
         return result == null ? Boolean.FALSE : result;
@@ -407,12 +427,15 @@
      *      field being validated.
      * @param  errors   The <code>ActionMessages</code> object to add errors to if any
      *      validation errors occur.
+     * @param validator The <code>Validator</code> instance, used to access
+     * other field values.
      * @param  request  Current request object.
      * @return true if valid, false otherwise.
      */
     public static Object validateFloat(Object bean,
                                       ValidatorAction va, Field field,
                                       ActionMessages errors,
+                                      Validator validator,
                                       HttpServletRequest request) {
         Object result = null;
         String value = null;
@@ -429,7 +452,7 @@
         result = GenericTypeValidator.formatFloat(value);
 
         if (result == null) {
-            errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
+            errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
         }
 
         return result == null ? Boolean.FALSE : result;
@@ -445,12 +468,15 @@
      *      field being validated.
      * @param  errors   The <code>ActionMessages</code> object to add errors to if any
      *      validation errors occur.
+     * @param validator The <code>Validator</code> instance, used to access
+     * other field values.
      * @param  request  Current request object.
      * @return true if valid, false otherwise.
      */
     public static Object validateDouble(Object bean,
                                         ValidatorAction va, Field field,
                                         ActionMessages errors,
+                                        Validator validator,
                                         HttpServletRequest request) {
         Object result = null;
         String value = null;
@@ -467,7 +493,7 @@
         result = GenericTypeValidator.formatDouble(value);
 
         if (result == null) {
-            errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
+            errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
         }
 
         return result == null ? Boolean.FALSE : result;
@@ -489,12 +515,15 @@
      *      field being validated.
      * @param  errors   The <code>ActionMessages</code> object to add errors to if any
      *      validation errors occur.
+     * @param validator The <code>Validator</code> instance, used to access
+     * other field values.
      * @param  request  Current request object.
      * @return true if valid, false otherwise.
      */
     public static Object validateDate(Object bean,
                                     ValidatorAction va, Field field,
                                     ActionMessages errors,
+                                    Validator validator,
                                     HttpServletRequest request) {
 
         Object result = null;
@@ -525,7 +554,7 @@
         }
 
         if (result == null) {
-            errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
+            errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
         }
 
         return result == null ? Boolean.FALSE : result;
@@ -541,12 +570,15 @@
      *      field being validated.
      * @param  errors   The <code>ActionMessages</code> object to add errors to if any
      *      validation errors occur.
+     * @param validator The <code>Validator</code> instance, used to access
+     * other field values.
      * @param  request  Current request object.
      * @return True if in range, false otherwise.
      */
     public static boolean validateIntRange(Object bean,
                                            ValidatorAction va, Field field,
                                            ActionMessages errors,
+                                           Validator validator,
                                            HttpServletRequest request) {
 
         String value = null;
@@ -563,12 +595,12 @@
                 int max = Integer.parseInt(field.getVarValue("max"));
 
                 if (!GenericValidator.isInRange(intValue, min, max)) {
-                    errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
+                    errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
 
                     return false;
                 }
             } catch (Exception e) {
-                errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
+                errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
                 return false;
             }
         }
@@ -586,12 +618,15 @@
      *      field being validated.
      * @param  errors   The <code>ActionMessages</code> object to add errors to if any
      *      validation errors occur.
+     * @param validator The <code>Validator</code> instance, used to access
+     * other field values.
      * @param  request  Current request object.
      * @return          True if in range, false otherwise.
      */
     public static boolean validateDoubleRange(Object bean,
                                               ValidatorAction va, Field field,
                                               ActionMessages errors,
+                                              Validator validator,
                                               HttpServletRequest request) {
 
         String value = null;
@@ -608,12 +643,12 @@
                 double max = Double.parseDouble(field.getVarValue("max"));
 
                 if (!GenericValidator.isInRange(doubleValue, min, max)) {
-                    errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
+                    errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
 
                     return false;
                 }
             } catch (Exception e) {
-                errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
+                errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
                 return false;
             }
         }
@@ -631,12 +666,15 @@
      *      field being validated.
      * @param  errors   The <code>ActionMessages</code> object to add errors to if any
      *      validation errors occur.
+     * @param validator The <code>Validator</code> instance, used to access
+     *      other field values.
      * @param  request  Current request object.
      * @return True if in range, false otherwise.
      */
     public static boolean validateFloatRange(Object bean,
                                              ValidatorAction va, Field field,
                                              ActionMessages errors,
+                                             Validator validator,
                                              HttpServletRequest request) {
 
         String value = null;
@@ -653,12 +691,12 @@
                 float max = Float.parseFloat(field.getVarValue("max"));
 
                 if (!GenericValidator.isInRange(floatValue, min, max)) {
-                    errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
+                    errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
 
                     return false;
                 }
             } catch (Exception e) {
-                errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
+                errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
                 return false;
             }
         }
@@ -676,12 +714,15 @@
      *      field being validated.
      * @param  errors   The <code>ActionMessages</code> object to add errors to if any
      *      validation errors occur.
+     * @param validator The <code>Validator</code> instance, used to access
+     *      other field values.
      * @param  request  Current request object.
      * @return true if valid, false otherwise.
      */
     public static Object validateCreditCard(Object bean,
                                           ValidatorAction va, Field field,
                                           ActionMessages errors,
+                                          Validator validator,
                                           HttpServletRequest request) {
 
         Object result = null;
@@ -699,7 +740,7 @@
         result = GenericTypeValidator.formatCreditCard(value);
 
         if (result == null) {
-            errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
+            errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
         }
 
         return result == null ? Boolean.FALSE : result;
@@ -716,12 +757,15 @@
      *      field being validated.
      * @param  errors   The <code>ActionMessages</code> object to add errors to if any
      *      validation errors occur.
+     * @param validator The <code>Validator</code> instance, used to access
+     *      other field values.
      * @param  request  Current request object.
      * @return True if valid, false otherwise.
      */
     public static boolean validateEmail(Object bean,
                                         ValidatorAction va, Field field,
                                         ActionMessages errors,
+                                        Validator validator,
                                         HttpServletRequest request) {
 
         String value = null;
@@ -732,7 +776,7 @@
         }
 
         if (!GenericValidator.isBlankOrNull(value) && !GenericValidator.isEmail(value)) {
-            errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
+            errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
             return false;
         } else {
             return true;
@@ -750,12 +794,15 @@
      *      field being validated.
      * @param  errors   The <code>ActionMessages</code> object to add errors to if any
      *      validation errors occur.
+     * @param validator The <code>Validator</code> instance, used to access
+     *      other field values.
      * @param  request  Current request object.
      * @return True if stated conditions met.
      */
     public static boolean validateMaxLength(Object bean,
                                             ValidatorAction va, Field field,
                                             ActionMessages errors,
+                                            Validator validator,
                                             HttpServletRequest request) {
 
         String value = null;
@@ -770,12 +817,12 @@
                 int max = Integer.parseInt(field.getVarValue("maxlength"));
 
                 if (!GenericValidator.maxLength(value, max)) {
-                    errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
+                    errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
 
                     return false;
                 }
             } catch (Exception e) {
-                errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
+                errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
                 return false;
             }
         }
@@ -794,12 +841,15 @@
      *      field being validated.
      * @param  errors   The <code>ActionMessages</code> object to add errors to if any
      *      validation errors occur.
+     * @param validator The <code>Validator</code> instance, used to access
+     *      other field values.
      * @param  request  Current request object.
      * @return True if stated conditions met.
      */
     public static boolean validateMinLength(Object bean,
                                             ValidatorAction va, Field field,
                                             ActionMessages errors,
+                                            Validator validator,
                                             HttpServletRequest request) {
 
         String value = null;
@@ -814,12 +864,12 @@
                 int min = Integer.parseInt(field.getVarValue("minlength"));
 
                 if (!GenericValidator.minLength(value, min)) {
-                    errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
+                    errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
 
                     return false;
                 }
             } catch (Exception e) {
-                errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
+                errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
                 return false;
             }
         }
@@ -852,12 +902,15 @@
      *      field being validated.
      * @param  errors   The <code>ActionMessages</code> object to add errors to if any
      *      validation errors occur.
+     * @param validator The <code>Validator</code> instance, used to access
+     *      other field values.
      * @param  request  Current request object.
      * @return True if valid, false otherwise.
      */
     public static boolean validateUrl(Object bean,
                                         ValidatorAction va, Field field,
                                         ActionMessages errors,
+                                        Validator validator,
                                         HttpServletRequest request) {
 
         String value = null;
@@ -890,7 +943,7 @@
             if (GenericValidator.isUrl(value)) {
                 return true;
             } else {
-                errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
+                errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
                 return false;
             }
         }
@@ -914,7 +967,7 @@
         if (urlValidator.isValid(value)) {
             return true;
         } else {
-            errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
+            errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
             return false;
         }
     }

Modified: struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/validator/Resources.java
URL: http://svn.apache.org/viewcvs/struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/validator/Resources.java?view=diff&r1=159290&r2=159291
==============================================================================
--- struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/validator/Resources.java (original)
+++ struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/validator/Resources.java Mon Mar 28 12:19:29 2005
@@ -25,6 +25,7 @@
 
 import org.apache.commons.validator.Arg;
 import org.apache.commons.validator.Field;
+import org.apache.commons.validator.Msg;
 import org.apache.commons.validator.Validator;
 import org.apache.commons.validator.ValidatorAction;
 import org.apache.commons.validator.ValidatorResources;
@@ -35,6 +36,7 @@
 import org.apache.struts.util.MessageResources;
 import org.apache.struts.util.ModuleUtils;
 import org.apache.struts.util.RequestUtils;
+import org.apache.struts.config.ModuleConfig;
 
 /**
  * This class helps provides some useful methods for retrieving objects
@@ -108,6 +110,41 @@
     }
 
     /**
+     * Retrieve <code>MessageResources</code> for the module and bundle.
+     * @param application the servlet context
+     * @param request the servlet request
+     * @param bundle the bundle key
+     */
+    public static MessageResources getMessageResources(
+        ServletContext application,
+        HttpServletRequest request,
+        String bundle) {
+
+        if (bundle == null) {
+            bundle = Globals.MESSAGES_KEY;
+        }
+
+        MessageResources resources = (MessageResources)request.getAttribute(bundle);
+
+        if (resources == null) {
+            ModuleConfig moduleConfig = ModuleUtils.getInstance()
+                                         .getModuleConfig(request, application);
+            resources = (MessageResources)application.getAttribute(bundle + moduleConfig.getPrefix());
+        }
+
+        if (resources == null) {
+            resources = (MessageResources)application.getAttribute(bundle);
+        }
+
+        if (resources == null) {
+            throw new NullPointerException("No message resources found for bundle: " + bundle);
+        }
+
+        return resources;
+
+    }
+
+    /**
      * Get the <code>Locale</code> of the current user.
      * @param request servlet request
      * @deprecated Use RequestUtils.getUserLocale() instead.  This will be removed
@@ -170,6 +207,52 @@
 
         return messages.getMessage(locale, msg, args);
     }
+    /**
+     * Gets the <code>Locale</code> sensitive value based on the key passed in.
+     * @param application the servlet context
+     * @param request the servlet request
+     * @param defaultMessages The default Message resources
+     * @param locale The locale
+     * @param va The Validator Action
+     * @param field The Validator Field
+     */
+    public static String getMessage(ServletContext application,
+                                    HttpServletRequest request,
+                                    MessageResources defaultMessages,
+                                    Locale locale,
+                                    ValidatorAction va,
+                                    Field field) {
+
+        Msg msg = field.getMessage(va.getName());
+        if (msg != null && !msg.isResource()) {
+            return msg.getKey();
+        }
+
+        String msgKey    = null;
+        String msgBundle = null;
+        MessageResources messages = defaultMessages;
+        if (msg == null) {
+           msgKey = va.getMsg();
+        } else {
+           msgKey    = msg.getKey();
+           msgBundle = msg.getBundle();
+           if (msg.getBundle() != null) {
+               messages = getMessageResources(application, request, msg.getBundle());
+           }
+        }
+
+        if (msgKey == null || msgKey.length() == 0) {
+            return "??? " + va.getName() + "." + field.getProperty() + " ???";
+        }
+
+        // Get the arguments
+        Arg[] args = field.getArgs(va.getName());
+        String[] argValues = getArgValues(application, request, messages, locale, args);
+
+        // Return the message
+        return messages.getMessage(locale, msgKey, argValues);
+
+    }
 
     /**
      * Gets the <code>ActionError</code> based on the 
@@ -230,6 +313,58 @@
     }
 
     /**
+     * Gets the <code>ActionMessage</code> based on the 
+     * <code>ValidatorAction</code> message and the <code>Field</code>'s 
+     * arg objects.
+     * @param validator the Validator
+     * @param request the servlet request
+     * @param va Validator action
+     * @param field the validator Field
+     */
+    public static ActionMessage getActionMessage(
+        Validator validator,
+        HttpServletRequest request,
+        ValidatorAction va,
+        Field field) {
+
+        Msg msg = field.getMessage(va.getName());
+        if (msg != null && !msg.isResource()) {
+            return new ActionMessage(msg.getKey(), false);
+        }
+
+        String msgKey    = null;
+        String msgBundle = null;
+        if (msg == null) {
+           msgKey = va.getMsg();
+        } else {
+           msgKey    = msg.getKey();
+           msgBundle = msg.getBundle();
+        }
+
+        if (msgKey == null || msgKey.length() == 0) {
+            return new ActionMessage("??? " + va.getName() + "." + field.getProperty() + " ???", false);
+        }
+
+        ServletContext application = (ServletContext)validator.getParameterValue(SERVLET_CONTEXT_PARAM);
+        MessageResources messages = getMessageResources(application, request, msgBundle);
+        Locale locale = RequestUtils.getUserLocale(request, null);
+
+        Arg[] args = field.getArgs(va.getName());
+        String[] argValues = getArgValues(application, request, messages, locale, args);
+
+        ActionMessage actionMessage = null;
+        if (msgBundle == null) {
+            actionMessage = new ActionMessage(msgKey, argValues);
+        } else {
+            String message = messages.getMessage(locale, msgKey, argValues);
+            actionMessage = new ActionMessage(message, false);
+        }
+        return actionMessage;
+
+    }
+
+
+    /**
      * Gets the message arguments based on the current 
      * <code>ValidatorAction</code> and <code>Field</code>.
      * @param actionName action name
@@ -266,6 +401,49 @@
         }
 
         return argMessages;
+    }
+
+    /**
+     * Gets the message arguments based on the current 
+     * <code>ValidatorAction</code> and <code>Field</code>.
+     * @param application the servlet context
+     * @param request the servlet request
+     * @param defaultMessages Default message resources
+     * @param locale the locale
+     * @param args The arguments for the message
+     */
+    private static String[] getArgValues(
+        ServletContext application,
+        HttpServletRequest request,
+        MessageResources defaultMessages,
+        Locale locale,
+        Arg[] args) {
+
+        if (args == null || args.length == 0) {
+            return null;
+        }
+
+        String[] values = new String[args.length];
+        for (int i = 0; i < args.length; i++) {
+            if (args[i] != null) {
+                if (args[i].isResource()) {
+
+                    MessageResources messages = defaultMessages;
+                    if (args[i].getBundle() != null) {
+                        messages = getMessageResources(application, request, args[i].getBundle());
+                    }
+                    values[i] = messages.getMessage(locale, args[i].getKey());
+
+                } else {
+
+                    values[i] = args[i].getKey();
+
+                }
+            }
+        }
+
+        return values;
+
     }
 
     /**

Modified: struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/validator/validwhen/ValidWhen.java
URL: http://svn.apache.org/viewcvs/struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/validator/validwhen/ValidWhen.java?view=diff&r1=159290&r2=159291
==============================================================================
--- struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/validator/validwhen/ValidWhen.java (original)
+++ struts/core/branches/STRUTS_1_2_BRANCH/src/share/org/apache/struts/validator/validwhen/ValidWhen.java Mon Mar 28 12:19:29 2005
@@ -117,7 +117,7 @@
             
             errors.add(
                 field.getKey(),
-                Resources.getActionMessage(request, va, field));
+                Resources.getActionMessage(validator, request, va, field));
                 
             return false;
         }
@@ -125,7 +125,7 @@
         if (!valid) {
             errors.add(
                 field.getKey(),
-                Resources.getActionMessage(request, va, field));
+                Resources.getActionMessage(validator, request, va, field));
                 
             return false;
         }



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