struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gvanma...@apache.org
Subject svn commit: r393130 [1/2] - in /struts/shale/trunk: ./ build/ clay-plugin/src/test/org/apache/shale/clay/config/ core-library/ core-library/src/conf/ core-library/src/java/org/apache/shale/component/ core-library/src/java/org/apache/shale/taglib/ core-...
Date Tue, 11 Apr 2006 01:43:46 GMT
Author: gvanmatre
Date: Mon Apr 10 18:43:42 2006
New Revision: 393130

URL: http://svn.apache.org/viewcvs?rev=393130&view=rev
Log:
Fix for Bug# 39121 - Implement use of Commons Validator Javascript. 

Modified:
    struts/shale/trunk/build.xml
    struts/shale/trunk/build/project.xml
    struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/AbstractTestCaseConfig.java
    struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/CommentTestCase.java
    struts/shale/trunk/core-library/build.xml
    struts/shale/trunk/core-library/src/conf/validator-rules.xml
    struts/shale/trunk/core-library/src/java/org/apache/shale/component/ValidatorScript.java
    struts/shale/trunk/core-library/src/java/org/apache/shale/taglib/ValidatorVarTag.java
    struts/shale/trunk/core-library/src/java/org/apache/shale/validator/CommonsValidator.java
    struts/shale/trunk/core-library/src/java/org/apache/shale/validator/messages.properties
    struts/shale/trunk/core-library/src/java/org/apache/shale/validator/messages_de.properties
    struts/shale/trunk/core-library/src/test/org/apache/shale/validator/CommonsValidatorTestCase.java
    struts/shale/trunk/core-library/src/test/org/apache/shale/validator/custom-rules.xml

Modified: struts/shale/trunk/build.xml
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/build.xml?rev=393130&r1=393129&r2=393130&view=diff
==============================================================================
--- struts/shale/trunk/build.xml (original)
+++ struts/shale/trunk/build.xml Mon Apr 10 18:43:42 2006
@@ -468,7 +468,7 @@
     <mkdir        dir="${lib.dir}/commons-validator"/>
     <get         dest="${lib.dir}/commons-validator/commons-validator.jar"
          ignoreerrors="true"
-                  src="${maven.repo}/commons-validator/jars/commons-validator-1.2.0.jar"
+                  src="${maven.repo}/commons-validator/jars/commons-validator-1.3.0.jar"
          usetimestamp="true"/>
 
     <mkdir        dir="${lib.dir}/creator"/>

Modified: struts/shale/trunk/build/project.xml
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/build/project.xml?rev=393130&r1=393129&r2=393130&view=diff
==============================================================================
--- struts/shale/trunk/build/project.xml (original)
+++ struts/shale/trunk/build/project.xml Mon Apr 10 18:43:42 2006
@@ -206,7 +206,7 @@
     <dependency>
       <groupId>commons-validator</groupId>
       <artifactId>commons-validator</artifactId>
-      <version>1.2.0</version>
+      <version>1.3.0</version>
       <url>jakarta.apache.org/commons/validator/</url>
       <properties>
         <war.bundle>true</war.bundle>

Modified: struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/AbstractTestCaseConfig.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/AbstractTestCaseConfig.java?rev=393130&r1=393129&r2=393130&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/AbstractTestCaseConfig.java (original)
+++ struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/AbstractTestCaseConfig.java Mon Apr 10 18:43:42 2006
@@ -84,7 +84,7 @@
     // load the mock converter config data
     protected void loadConverters() {
         for (int i = 0; i < CONVERTERS.length; i++) {
-           application.addComponent(((String[])CONVERTERS[i])[1], ((String[])CONVERTERS[i])[2]);
+           application.addConverter(((String[])CONVERTERS[i])[1], ((String[])CONVERTERS[i])[2]);
         }
      }
     
@@ -96,7 +96,7 @@
     // load the mock validator config
     protected void loadValidators() {
         for (int i = 0; i < VALIDATORS.length; i++) {
-           application.addComponent(((String[])VALIDATORS[i])[1], ((String[])VALIDATORS[i])[2]);
+           application.addValidator(((String[])VALIDATORS[i])[1], ((String[])VALIDATORS[i])[2]);
         }
     }
 

Modified: struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/CommentTestCase.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/CommentTestCase.java?rev=393130&r1=393129&r2=393130&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/CommentTestCase.java (original)
+++ struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/CommentTestCase.java Mon Apr 10 18:43:42 2006
@@ -66,10 +66,7 @@
         
         //Utility class is loaded as a managed bean in shale_core/META-INF/faces-config.xml
         servletContext.setAttribute(ShaleConstants.TAG_UTILITY_BEAN, new Tags());
-        
-        //It's necessary to explicitly set the kit id because it's lost when using the Sun RI. 
-        facesContext.getViewRoot().setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
-        
+                
         //loads the RI or myfaces renderers from the RENDERERS static array.
         for (int i = 0; i < RENDERERS.length; i++) {
             

Modified: struts/shale/trunk/core-library/build.xml
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/build.xml?rev=393130&r1=393129&r2=393130&view=diff
==============================================================================
--- struts/shale/trunk/core-library/build.xml (original)
+++ struts/shale/trunk/core-library/build.xml Mon Apr 10 18:43:42 2006
@@ -129,6 +129,7 @@
     <pathelement location="${jsf-impl.jar}"/>
     <pathelement location="${jsp-api.jar}"/>
     <pathelement location="${junit.jar}"/>
+    <pathelement location="${jakarta-oro.jar}"/>
     <pathelement location="${servlet-api.jar}"/>
     <pathelement location="${shale-test.jar}"/>
     <pathelement location="${spring-beans.jar}"/>

Modified: struts/shale/trunk/core-library/src/conf/validator-rules.xml
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/conf/validator-rules.xml?rev=393130&r1=393129&r2=393130&view=diff
==============================================================================
--- struts/shale/trunk/core-library/src/conf/validator-rules.xml (original)
+++ struts/shale/trunk/core-library/src/conf/validator-rules.xml Mon Apr 10 18:43:42 2006
@@ -1,897 +1,180 @@
-<!DOCTYPE form-validation PUBLIC
-     "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.2.0//EN"
-     "http://jakarta.apache.org/commons/dtds/validator_1_2_0.dtd">
-
-<form-validation>
-
-   <global>
-
-      <validator name="required"
-            classname="org.apache.shale.validator.CommonsValidator"
-               method="isSupplied"
-         methodParams="java.lang.String"
-                  msg="errors.required">
-
-         <javascript><![CDATA[
-            function validateRequired(form) {
-                var isValid = true;
-                var focusField = null;
-                var i = 0;
-                var fields = new Array();
-                oRequired = new required();
-                for (x in oRequired) {
-                   var field = form[oRequired[x][0]];
-                   
-                    if (field.type == 'text' ||
-                        field.type == 'textarea' ||
-                        field.type == 'file' ||
-                        field.type == 'select-one' ||
-                        field.type == 'radio' ||
-                        field.type == 'password') {
-                        
-                        var value = '';
-                  // get field's value
-                  if (field.type == "select-one") {
-                     var si = field.selectedIndex;
-                     if (si >= 0) {
-                        value = field.options[si].value;
-                     }
-                  } else {
-                     value = field.value;
-                  }
-                        
-                        if (trim(value).length == 0) {
-                        
-                           if (i == 0) {
-                               focusField = field;
-                           }
-                           fields[i++] = oRequired[x][1];
-                           isValid = false;
-                        }
-                    }
-                }
-                if (fields.length > 0) {
-                   focusField.focus();
-                   alert(fields.join('\n'));
-                }
-                return isValid;
-            }
-            
-            // Trim whitespace from left and right sides of s.
-            function trim(s) {
-                return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
-            }
-            
-            ]]>
-         </javascript>
-
-      </validator>
-
-      <validator name="minlength"
-            classname="org.apache.commons.validator.GenericValidator"
-               method="minLength"
-         methodParams="java.lang.String,int"
-              depends=""
-                  msg="errors.minlength">
-
-         <javascript><![CDATA[
-            function validateMinLength(form) {
-                var isValid = true;
-                var focusField = null;
-                var i = 0;
-                var fields = new Array();
-                oMinLength = new minlength();
-                for (x in oMinLength) {
-                    var field = form[oMinLength[x][0]];
-                    
-                    if (field.type == 'text' ||
-                        field.type == 'textarea') {
-                        
-                        var iMin = parseInt(oMinLength[x][2]("minlength"));
-                        if ((trim(field.value).length > 0) && (field.value.length < iMin)) {
-                            if (i == 0) {
-                                focusField = field;
-                            }
-                            fields[i++] = oMinLength[x][1];
-                            isValid = false;
-                        }
-                    }
-                }
-                if (fields.length > 0) {
-                   focusField.focus();
-                   alert(fields.join('\n'));
-                }
-                return isValid;
-            }]]>
-         </javascript>
-
-      </validator>
-
-
-      <validator name="maxlength"
-            classname="org.apache.commons.validator.GenericValidator"
-               method="maxLength"
-         methodParams="java.lang.String,int"
-              depends=""
-                  msg="errors.maxlength">
-
-         <javascript><![CDATA[
-            function validateMaxLength(form) {
-                var isValid = true;
-                var focusField = null;
-                var i = 0;
-                var fields = new Array();
-                oMaxLength = new maxlength();
-                for (x in oMaxLength) {
-                    var field = form[oMaxLength[x][0]];
-                    
-                    if (field.type == 'text' ||
-                        field.type == 'textarea') {
-                        
-                        var iMax = parseInt(oMaxLength[x][2]("maxlength"));
-                        if (field.value.length > iMax) {
-                            if (i == 0) {
-                                focusField = field;
-                            }
-                            fields[i++] = oMaxLength[x][1];
-                            isValid = false;
-                        }
-                    }
-                }
-                if (fields.length > 0) {
-                   focusField.focus();
-                   alert(fields.join('\n'));
-                }
-                return isValid;
-            }]]>
-         </javascript>
-
-      </validator>
-
-
-      <validator name="mask"
-            classname="org.apache.commons.validator.GenericValidator"
-               method="matchRegexp"
-         methodParams="java.lang.String,java.lang.String"
-              depends=""
-                  msg="errors.invalid">
-
-         <javascript><![CDATA[
-            function validateMask(form) {
-                var isValid = true;
-                var focusField = null;
-                var i = 0;
-                var fields = new Array();
-                oMasked = new mask();
-                for (x in oMasked) {
-                    var field = form[oMasked[x][0]];
-                    
-                    if ((field.type == 'text' || 
-                         field.type == 'textarea') && 
-                         (field.value.length > 0)) {
-                        
-                        if (!matchPattern(field.value, oMasked[x][2]("mask"))) {
-                            if (i == 0) {
-                                focusField = field;
-                            }
-                            fields[i++] = oMasked[x][1];
-                            isValid = false;
-                        }
-                    }
-                }
-                
-                if (fields.length > 0) {
-                   focusField.focus();
-                   alert(fields.join('\n'));
-                }
-                return isValid;
-            }
-
-            function matchPattern(value, mask) {
-               return mask.exec(value);
-            }]]>
-         </javascript>
-
-      </validator>
-
-
-      <validator name="byte"
-            classname="org.apache.commons.validator.GenericValidator"
-               method="isByte"
-         methodParams="java.lang.String"
-              depends=""
-                  msg="errors.byte"
-       jsFunctionName="ByteValidations">
-
-         <javascript><![CDATA[
-            function validateByte(form) {
-                var bValid = true;
-                var focusField = null;
-                var i = 0;
-                var fields = new Array();
-                oByte = new ByteValidations();
-                for (x in oByte) {
-                   var field = form[oByte[x][0]];
-                   
-                    if (field.type == 'text' ||
-                        field.type == 'textarea' ||
-                        field.type == 'select-one' ||
-                  field.type == 'radio') {
-
-                  var value = '';
-                  // get field's value
-                  if (field.type == "select-one") {
-                     var si = field.selectedIndex;
-                     if (si >= 0) {
-                        value = field.options[si].value;
-                     }
-                  } else {
-                     value = field.value;
-                  }
-                        
-                        if (value.length > 0) {
-                            if (!isAllDigits(value)) {
-                                bValid = false;
-                                if (i == 0) {
-                                    focusField = field;
-                                }
-                                fields[i++] = oByte[x][1];
-
-                            } else {
-
-                               var iValue = parseInt(value);
-                               if (isNaN(iValue) || !(iValue >= -128 && iValue <= 127)) {
-                                   if (i == 0) {
-                                       focusField = field;
-                                   }
-                                   fields[i++] = oByte[x][1];
-                                   bValid = false;
-                               }
-                            }
-                  }
-                  
-                    }
-                }
-                if (fields.length > 0) {
-                   focusField.focus();
-                   alert(fields.join('\n'));
-                }
-                return bValid;
-            }]]>
-         </javascript>
-
-      </validator>
+<!DOCTYPE form-validation PUBLIC 
+           "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1.3//EN" 
+           "http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd">
 
 
-      <validator name="short"
-            classname="org.apache.commons.validator.GenericValidator"
-               method="isShort"
-         methodParams="java.lang.String"
-              depends=""
-                  msg="errors.short"
-       jsFunctionName="ShortValidations">
-
-         <javascript><![CDATA[
-            function validateShort(form) {
-                var bValid = true;
-                var focusField = null;
-                var i = 0;
-                var fields = new Array();
-                oShort = new ShortValidations();
-                for (x in oShort) {
-                   var field = form[oShort[x][0]];
-                   
-                    if (field.type == 'text' ||
-                        field.type == 'textarea' ||
-                        field.type == 'select-one' ||
-                        field.type == 'radio') {
-                        
-                        var value = '';
-                  // get field's value
-                  if (field.type == "select-one") {
-                     var si = field.selectedIndex;
-                     if (si >= 0) {
-                        value = field.options[si].value;
-                     }
-                  } else {
-                     value = field.value;
-                  }
-                        
-                        if (value.length > 0) {
-                            if (!isAllDigits(value)) {
-                                bValid = false;
-                                if (i == 0) {
-                                    focusField = field;
-                                }
-                                fields[i++] = oShort[x][1];
-
-                            } else {
-                        
-                               var iValue = parseInt(value);
-                               if (isNaN(iValue) || !(iValue >= -32768 && iValue <= 32767)) {
-                                   if (i == 0) {
-                                       focusField = field;
-                                   }
-                                   fields[i++] = oShort[x][1];
-                                   bValid = false;
-                               }
-                          }
-                       }
-                    }
-                }
-                if (fields.length > 0) {
-                   focusField.focus();
-                   alert(fields.join('\n'));
-                }
-                return bValid;
-            }]]>
-         </javascript>
-
-      </validator>
-
-
-      <validator name="integer"
-            classname="org.apache.commons.validator.GenericValidator"
-               method="isInt"
-         methodParams="java.lang.String"
-              depends=""
-                  msg="errors.integer"
-       jsFunctionName="IntegerValidations">
-
-         <javascript><![CDATA[
-            function validateInteger(form) {
-                var bValid = true;
-                var focusField = null;
-                var i = 0;
-                var fields = new Array();
-                oInteger = new IntegerValidations();
-                for (x in oInteger) {
-                   var field = form[oInteger[x][0]];
-
-                    if (field.type == 'text' ||
-                        field.type == 'textarea' ||
-                        field.type == 'select-one' ||
-                        field.type == 'radio') {
-                        
-                        var value = '';
-                  // get field's value
-                  if (field.type == "select-one") {
-                     var si = field.selectedIndex;
-                      if (si >= 0) {
-                         value = field.options[si].value;
-                      }
-                  } else {
-                     value = field.value;
-                  }
-                        
-                        if (value.length > 0) {
-                        
-                            if (!isAllDigits(value)) {
-                                bValid = false;
-                                if (i == 0) {
-                                   focusField = field;
-                               }
-                          fields[i++] = oInteger[x][1];
-                          
-                            } else {
-                               var iValue = parseInt(value);
-                               if (isNaN(iValue) || !(iValue >= -2147483648 && iValue <= 2147483647)) {
-                                   if (i == 0) {
-                                       focusField = field;
-                                   }
-                                   fields[i++] = oInteger[x][1];
-                                   bValid = false;
-                              }
-                           }
-                       }
-                    }
-                }
-                if (fields.length > 0) {
-                   focusField.focus();
-                   alert(fields.join('\n'));
-                }
-                return bValid;
-            }
-
-            function isAllDigits(argvalue) {
-                argvalue = argvalue.toString();
-                var validChars = "0123456789";
-                var startFrom = 0;
-                if (argvalue.substring(0, 2) == "0x") {
-                   validChars = "0123456789abcdefABCDEF";
-                   startFrom = 2;
-                } else if (argvalue.charAt(0) == "0") {
-                   validChars = "01234567";
-                   startFrom = 1;
-                } else if (argvalue.charAt(0) == "-") {
-                    startFrom = 1;
-                }
-                
-                for (var n = startFrom; n < argvalue.length; n++) {
-                    if (validChars.indexOf(argvalue.substring(n, n+1)) == -1) return false;
-                }
-                return true;
-            }]]>
-         </javascript>
-
-      </validator>
-
-      <validator name="float"
-            classname="org.apache.commons.validator.GenericValidator"
-               method="isDouble"
-         methodParams="java.lang.String"
-              depends=""
-                  msg="errors.float"
-       jsFunctionName="FloatValidations">
-
-         <javascript><![CDATA[
-            function validateFloat(form) {
-                var bValid = true;
-                var focusField = null;
-                var i = 0;
-                var fields = new Array();
-                oFloat = new FloatValidations();
-                for (x in oFloat) {
-                   var field = form[oFloat[x][0]];
-                   
-                    if (field.type == 'text' ||
-                        field.type == 'textarea' ||
-                        field.type == 'select-one' ||
-                        field.type == 'radio') {
-                        
-                       var value = '';
-                  // get field's value
-                  if (field.type == "select-one") {
-                     var si = field.selectedIndex;
-                     if (si >= 0) {
-                         value = field.options[si].value;
-                     }
-                  } else {
-                     value = field.value;
-                  }
-                        
-                        if (value.length > 0) {
-                            // remove '.' before checking digits
-                            var tempArray = value.split('.');
-                            var joinedString= tempArray.join('');
-
-                            if (!isAllDigits(joinedString)) {
-                                bValid = false;
-                                if (i == 0) {
-                                    focusField = field;
-                                }
-                                fields[i++] = oFloat[x][1];
-
-                            } else {
-                               var iValue = parseFloat(value);
-                               if (isNaN(iValue)) {
-                                   if (i == 0) {
-                                       focusField = field;
-                                   }
-                                   fields[i++] = oFloat[x][1];
-                                   bValid = false;
-                               }
-                            }
-                        }
-                    }
-                }
-                if (fields.length > 0) {
-                   focusField.focus();
-                   alert(fields.join('\n'));
-                }
-                return bValid;
-            }]]>
-         </javascript>
-
-      </validator>
-
-      <validator name="date"
-            classname="org.apache.shale.validator.CommonsValidator"
-               method="isDate"
-         methodParams="java.lang.String,java.lang.String"
-              depends=""
-                  msg="errors.date"
-       jsFunctionName="DateValidations">
-
-         <javascript><![CDATA[
-            function validateDate(form) {
-               var bValid = true;
-               var focusField = null;
-               var i = 0;
-               var fields = new Array();
-               oDate = new DateValidations();
-               for (x in oDate) {
-                   var value = form[oDate[x][0]].value;
-                   var datePattern = oDate[x][2]("datePatternStrict");
-                   if ((form[oDate[x][0]].type == 'text' ||
-                        form[oDate[x][0]].type == 'textarea') &&
-                       (value.length > 0) &&
-                       (datePattern.length > 0)) {
-                     var MONTH = "MM";
-                     var DAY = "dd";
-                     var YEAR = "yyyy";
-                     var orderMonth = datePattern.indexOf(MONTH);
-                     var orderDay = datePattern.indexOf(DAY);
-                     var orderYear = datePattern.indexOf(YEAR);
-                     if ((orderDay < orderYear && orderDay > orderMonth)) {
-                         var iDelim1 = orderMonth + MONTH.length;
-                         var iDelim2 = orderDay + DAY.length;
-                         var delim1 = datePattern.substring(iDelim1, iDelim1 + 1);
-                         var delim2 = datePattern.substring(iDelim2, iDelim2 + 1);
-                         if (iDelim1 == orderDay && iDelim2 == orderYear) {
-                            dateRegexp = new RegExp("^(\\d{2})(\\d{2})(\\d{4})$");
-                         } else if (iDelim1 == orderDay) {
-                            dateRegexp = new RegExp("^(\\d{2})(\\d{2})[" + delim2 + "](\\d{4})$");
-                         } else if (iDelim2 == orderYear) {
-                            dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})(\\d{4})$");
-                         } else {
-                            dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{4})$");
-                         }
-                         var matched = dateRegexp.exec(value);
-                         if(matched != null) {
-                            if (!isValidDate(matched[2], matched[1], matched[3])) {
-                               if (i == 0) {
-                                   focusField = form[oDate[x][0]];
-                               }
-                               fields[i++] = oDate[x][1];
-                               bValid =  false;
-                            }
-                         } else {
-                            if (i == 0) {
-                                focusField = form[oDate[x][0]];
-                            }
-                            fields[i++] = oDate[x][1];
-                            bValid =  false;
-                         }
-                     } else if ((orderMonth < orderYear && orderMonth > orderDay)) {
-                         var iDelim1 = orderDay + DAY.length;
-                         var iDelim2 = orderMonth + MONTH.length;
-                         var delim1 = datePattern.substring(iDelim1, iDelim1 + 1);
-                         var delim2 = datePattern.substring(iDelim2, iDelim2 + 1);
-                         if (iDelim1 == orderMonth && iDelim2 == orderYear) {
-                             dateRegexp = new RegExp("^(\\d{2})(\\d{2})(\\d{4})$");
-                         } else if (iDelim1 == orderMonth) {
-                             dateRegexp = new RegExp("^(\\d{2})(\\d{2})[" + delim2 + "](\\d{4})$");
-                         } else if (iDelim2 == orderYear) {
-                             dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})(\\d{4})$");
-                         } else {
-                             dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{4})$");
-                         }
-                         var matched = dateRegexp.exec(value);
-                         if(matched != null) {
-                             if (!isValidDate(matched[1], matched[2], matched[3])) {
-                                 if (i == 0) {
-                                     focusField = form[oDate[x][0]];
-                                 }
-                                 fields[i++] = oDate[x][1];
-                                 bValid =  false;
-                              }
-                         } else {
-                             if (i == 0) {
-                                 focusField = form[oDate[x][0]];
-                             }
-                             fields[i++] = oDate[x][1];
-                             bValid =  false;
-                         }
-                     } else if ((orderMonth > orderYear && orderMonth < orderDay)) {
-                         var iDelim1 = orderYear + YEAR.length;
-                         var iDelim2 = orderMonth + MONTH.length;
-                         var delim1 = datePattern.substring(iDelim1, iDelim1 + 1);
-                         var delim2 = datePattern.substring(iDelim2, iDelim2 + 1);
-                         if (iDelim1 == orderMonth && iDelim2 == orderDay) {
-                             dateRegexp = new RegExp("^(\\d{4})(\\d{2})(\\d{2})$");
-                         } else if (iDelim1 == orderMonth) {
-                             dateRegexp = new RegExp("^(\\d{4})(\\d{2})[" + delim2 + "](\\d{2})$");
-                         } else if (iDelim2 == orderDay) {
-                             dateRegexp = new RegExp("^(\\d{4})[" + delim1 + "](\\d{2})(\\d{2})$");
-                         } else {
-                             dateRegexp = new RegExp("^(\\d{4})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{2})$");
-                         }
-                         var matched = dateRegexp.exec(value);
-                         if(matched != null) {
-                             if (!isValidDate(matched[3], matched[2], matched[1])) {
-                                 if (i == 0) {
-                                     focusField = form[oDate[x][0]];
-                                  }
-                                  fields[i++] = oDate[x][1];
-                                  bValid =  false;
-                              }
-                          } else {
-                              if (i == 0) {
-                                  focusField = form[oDate[x][0]];
-                              }
-                              fields[i++] = oDate[x][1];
-                              bValid =  false;
-                          }
-                     } else {
-                         if (i == 0) {
-                             focusField = form[oDate[x][0]];
-                         }
-                         fields[i++] = oDate[x][1];
-                         bValid =  false;
-                     }
-                  }
-               }
-               if (fields.length > 0) {
-                  focusField.focus();
-                  alert(fields.join('\n'));
-               }
-               return bValid;
-            }
-
-       function isValidDate(day, month, year) {
-           if (month < 1 || month > 12) {
-                    return false;
-                }
-                if (day < 1 || day > 31) {
-                    return false;
-                }
-                if ((month == 4 || month == 6 || month == 9 || month == 11) &&
-                    (day == 31)) {
-                    return false;
-                }
-                if (month == 2) {
-                    var leap = (year % 4 == 0 &&
-                               (year % 100 != 0 || year % 400 == 0));
-                    if (day>29 || (day == 29 && !leap)) {
-                        return false;
-                    }
-                }
-                return true;
-            }]]>
-         </javascript>
-
-      </validator>
-
-      <validator name="intRange"
-            classname="org.apache.commons.validator.GenericValidator"
-               method="isInRange"
-         methodParams="int,int,int"
-              depends="integer"
-                  msg="errors.range">
-
-         <javascript><![CDATA[
-            function validateIntRange(form) {
-                var isValid = true;
-                var focusField = null;
-                var i = 0;
-                var fields = new Array();
-                oRange = new intRange();
-                for (x in oRange) {
-                    var field = form[oRange[x][0]];
-                    
-                    if ((field.type == 'text' ||
-                         field.type == 'textarea') &&
-                        (field.value.length > 0)) {
-                        
-                        var iMin = parseInt(oRange[x][2]("min"));
-                        var iMax = parseInt(oRange[x][2]("max"));
-                        var iValue = parseInt(field.value);
-                        if (!(iValue >= iMin && iValue <= iMax)) {
-                            if (i == 0) {
-                                focusField = field;
-                            }
-                            fields[i++] = oRange[x][1];
-                            isValid = false;
-                        }
-                    }
-                }
-                if (fields.length > 0) {
-                    focusField.focus();
-                    alert(fields.join('\n'));
-                }
-                return isValid;
-            }]]>
-         </javascript>
-
-      </validator>
-
-      <validator name="floatRange"
-            classname="org.apache.commons.validator.GenericValidator"
-               method="isInRange"
-         methodParams="double,double,double"
-              depends="float"
-                  msg="errors.range">
-
-         <javascript><![CDATA[
-            function validateFloatRange(form) {
-                var isValid = true;
-                var focusField = null;
-                var i = 0;
-                var fields = new Array();
-                oRange = new floatRange();
-                for (x in oRange) {
-                    var field = form[oRange[x][0]];
-                    
-                    if ((field.type == 'text' ||
-                         field.type == 'textarea') &&
-                        (field.value.length > 0)) {
-                        
-                        var fMin = parseFloat(oRange[x][2]("min"));
-                        var fMax = parseFloat(oRange[x][2]("max"));
-                        var fValue = parseFloat(field.value);
-                        if (!(fValue >= fMin && fValue <= fMax)) {
-                            if (i == 0) {
-                                focusField = field;
-                            }
-                            fields[i++] = oRange[x][1];
-                            isValid = false;
-                        }
-                    }
-                }
-                if (fields.length > 0) {
-                    focusField.focus();
-                    alert(fields.join('\n'));
-                }
-                return isValid;
-            }]]>
-         </javascript>
-
-      </validator>
-
-      <validator name="creditCard"
-            classname="org.apache.commons.validator.GenericValidator"
-               method="isCreditCard"
-         methodParams="java.lang.String"
-              depends=""
-                  msg="errors.creditcard">
-
-         <javascript><![CDATA[
-            function validateCreditCard(form) {
-                var bValid = true;
-                var focusField = null;
-                var i = 0;
-                var fields = new Array();
-                oCreditCard = new creditCard();
-                for (x in oCreditCard) {
-                    if ((form[oCreditCard[x][0]].type == 'text' ||
-                         form[oCreditCard[x][0]].type == 'textarea') &&
-                        (form[oCreditCard[x][0]].value.length > 0)) {
-                        if (!luhnCheck(form[oCreditCard[x][0]].value)) {
-                            if (i == 0) {
-                                focusField = form[oCreditCard[x][0]];
-                            }
-                            fields[i++] = oCreditCard[x][1];
-                            bValid = false;
-                        }
-                    }
-                }
-                if (fields.length > 0) {
-                    focusField.focus();
-                    alert(fields.join('\n'));
-                }
-                return bValid;
-            }
-
-            /**
-             * Reference: http://www.ling.nwu.edu/~sburke/pub/luhn_lib.pl
-             */
-            function luhnCheck(cardNumber) {
-                if (isLuhnNum(cardNumber)) {
-                    var no_digit = cardNumber.length;
-                    var oddoeven = no_digit & 1;
-                    var sum = 0;
-                    for (var count = 0; count < no_digit; count++) {
-                        var digit = parseInt(cardNumber.charAt(count));
-                        if (!((count & 1) ^ oddoeven)) {
-                            digit *= 2;
-                            if (digit > 9) digit -= 9;
-                        };
-                        sum += digit;
-                    };
-                    if (sum == 0) return false;
-                    if (sum % 10 == 0) return true;
-                };
-                return false;
-            }
-
-            function isLuhnNum(argvalue) {
-                argvalue = argvalue.toString();
-                if (argvalue.length == 0) {
-                    return false;
-                }
-                for (var n = 0; n < argvalue.length; n++) {
-                    if ((argvalue.substring(n, n+1) < "0") ||
-                        (argvalue.substring(n,n+1) > "9")) {
-                        return false;
-                    }
-                }
-                return true;
-            }]]>
-         </javascript>
-
-      </validator>
+<form-validation>
 
+	<global>
 
-      <validator name="email"
-            classname="org.apache.commons.validator.GenericValidator"
-               method="isEmail"
-         methodParams="java.lang.String"
-              depends=""
-                  msg="errors.email">
-
-         <javascript><![CDATA[
-            function validateEmail(form) {
-                var bValid = true;
-                var focusField = null;
-                var i = 0;
-                var fields = new Array();
-                oEmail = new email();
-                for (x in oEmail) {
-                    if ((form[oEmail[x][0]].type == 'text' ||
-                         form[oEmail[x][0]].type == 'textarea') &&
-                        (form[oEmail[x][0]].value.length > 0)) {
-                        if (!checkEmail(form[oEmail[x][0]].value)) {
-                            if (i == 0) {
-                                focusField = form[oEmail[x][0]];
-                            }
-                            fields[i++] = oEmail[x][1];
-                            bValid = false;
-                        }
-                    }
-                }
-                if (fields.length > 0) {
-                    focusField.focus();
-                    alert(fields.join('\n'));
-                }
-                return bValid;
-            }
-
-            /**
-             * Reference: Sandeep V. Tamhankar (stamhankar@hotmail.com),
-             * http://javascript.internet.com
-             */
-            function checkEmail(emailStr) {
-               if (emailStr.length == 0) {
-                   return true;
-               }
-               var emailPat=/^(.+)@(.+)$/;
-               var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
-               var validChars="\[^\\s" + specialChars + "\]";
-               var quotedUser="(\"[^\"]*\")";
-               var ipDomainPat=/^(\d{1,3})[.](\d{1,3})[.](\d{1,3})[.](\d{1,3})$/;
-               var atom=validChars + '+';
-               var word="(" + atom + "|" + quotedUser + ")";
-               var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
-               var domainPat=new RegExp("^" + atom + "(\\." + atom + ")*$");
-               var matchArray=emailStr.match(emailPat);
-               if (matchArray == null) {
-                   return false;
-               }
-               var user=matchArray[1];
-               var domain=matchArray[2];
-               if (user.match(userPat) == null) {
-                   return false;
-               }
-               var IPArray = domain.match(ipDomainPat);
-               if (IPArray != null) {
-                   for (var i = 1; i <= 4; i++) {
-                      if (IPArray[i] > 255) {
-                         return false;
-                      }
-                   }
-                   return true;
-               }
-               var domainArray=domain.match(domainPat);
-               if (domainArray == null) {
-                   return false;
-               }
-               var atomPat=new RegExp(atom,"g");
-               var domArr=domain.match(atomPat);
-               var len=domArr.length;
-               if ((domArr[domArr.length-1].length < 2) ||
-                   (domArr[domArr.length-1].length > 3)) {
-                   return false;
-               }
-               if (len < 2) {
-                   return false;
-               }
-               return true;
-            }]]>
-         </javascript>
 
-      </validator>
+		<validator name="required"
+			classname="org.apache.shale.validator.CommonsValidator"
+			method="isSupplied" 
+			methodParams="java.lang.String"
+			msg="errors.required"
+			jsFunction="org.apache.commons.validator.javascript.validateRequired" 
+			jsFunctionName="validateRequired"
+			depends=""/>
+
+
+		<validator name="maxlength"
+			classname="org.apache.commons.validator.GenericValidator"
+			method="maxLength"
+			methodParams="java.lang.String,int"
+			msg="errors.maxlength"
+			jsFunctionName="validateMaxLength"
+			jsFunction="org.apache.commons.validator.javascript.validateMaxLength"
+			depends=""/>
+
+
+		<validator name="minlength"
+			classname="org.apache.commons.validator.GenericValidator"
+			method="minLength"
+			methodParams="java.lang.String,int"
+			msg="errors.minlength"
+			jsFunctionName="validateMinLength"
+			jsFunction="org.apache.commons.validator.javascript.validateMinLength"
+			depends=""/>
+
+
+		<validator name="mask"
+			classname="org.apache.commons.validator.GenericValidator"
+			method="matchRegexp"
+			methodParams="java.lang.String,java.lang.String"
+			msg="errors.invalid"
+			jsFunctionName="validateMask"
+			jsFunction="org.apache.commons.validator.javascript.validateMask"			
+			depends=""/>
+
+
+
+		<validator name="byte"
+			classname="org.apache.commons.validator.GenericValidator"
+			method="isByte"
+			methodParams="java.lang.String"
+			msg="errors.byte"
+			jsFunctionName="validateByte"
+			jsFunction="org.apache.commons.validator.javascript.validateByte"			
+			depends=""/>
+
+
+		<validator name="short"
+			classname="org.apache.commons.validator.GenericValidator"
+			method="isShort"
+			methodParams="java.lang.String"
+			msg="errors.short"
+			jsFunctionName="validateShort"
+			jsFunction="org.apache.commons.validator.javascript.validateShort"			
+			depends=""/>
+
+		<validator name="integer"
+			classname="org.apache.commons.validator.GenericValidator"
+			method="isInt"
+			methodParams="java.lang.String"
+			msg="errors.integer"
+			jsFunctionName="validateInteger"
+			jsFunction="org.apache.commons.validator.javascript.validateInteger"			
+			depends=""/>
+
+
+		<validator name="long"
+			classname="org.apache.commons.validator.GenericValidator"
+			method="isLong"
+			methodParams="java.lang.String"
+			msg="errors.long"
+			depends=""/>
+
+
+		<validator name="float"
+			classname="org.apache.commons.validator.GenericValidator"
+			method="isFloat"
+			methodParams="java.lang.String"
+			msg="errors.float"
+			jsFunctionName="validateFloat"
+			jsFunction="org.apache.commons.validator.javascript.validateFloat"			
+			depends=""/>
+
+		<validator name="double"
+			classname="org.apache.commons.validator.GenericValidator"
+			method="isDouble"
+			methodParams="java.lang.String"
+			msg="errors.double"
+			depends=""/>
+
+		<validator name="date"
+			classname="org.apache.shale.validator.CommonsValidator"
+			method="isDate"
+			methodParams="java.lang.String,java.lang.String"
+			msg="errors.date"
+			jsFunctionName="validateDate"
+			jsFunction="org.apache.commons.validator.javascript.validateDate"			
+			depends=""/>
+
+
+		<validator name="intRange"
+			classname="org.apache.commons.validator.GenericValidator"
+			method="isInRange"
+			methodParams="int,int,int"
+			msg="errors.range"
+			jsFunctionName="validateIntRange"
+			jsFunction="org.apache.commons.validator.javascript.validateIntRange"			
+			depends="integer"/>
+
+
+		<validator name="floatRange"
+			classname="org.apache.commons.validator.GenericValidator"
+			method="isInRange"
+			methodParams="float,float,float"
+			msg="errors.range"
+			jsFunctionName="validateFloatRange"
+			jsFunction="org.apache.commons.validator.javascript.validateFloatRange"			
+			depends="float"/>
+
+		<validator name="doubleRange"
+			classname="org.apache.commons.validator.GenericValidator"
+			method="isInRange"
+			methodParams="double,double,double"
+			msg="errors.range"
+			depends="double"/>
+
+
+		<validator name="creditCard"
+			classname="org.apache.commons.validator.GenericValidator"
+			method="isCreditCard"
+			methodParams="java.lang.String"
+			msg="errors.creditcard"
+			jsFunctionName="validateCreditCard"
+			jsFunction="org.apache.commons.validator.javascript.validateCreditCard"			
+			depends=""/>
+			
+
+		<validator name="email"
+			classname="org.apache.commons.validator.GenericValidator"
+			method="isEmail"
+			methodParams="java.lang.String"
+			msg="errors.email"
+			jsFunctionName="validateEmail"
+			jsFunction="org.apache.commons.validator.javascript.validateEmail"			
+			depends=""/>
+
+        <validator name="url"
+            classname="org.apache.commons.validator.GenericValidator"
+                   method="isUrl"
+                   methodParams="java.lang.String"
+                   depends=""
+                   msg="errors.url"/>
+
+
+
+        <validator name="includeJavaScriptUtilities"
+                   classname=""
+                   method=""
+                   methodParams=""
+                   depends=""
+                   msg=""
+                   jsFunction="org.apache.commons.validator.javascript.validateUtilities"/>
 
-   </global>
+	</global>
 
 </form-validation>

Modified: struts/shale/trunk/core-library/src/java/org/apache/shale/component/ValidatorScript.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/java/org/apache/shale/component/ValidatorScript.java?rev=393130&r1=393129&r2=393130&view=diff
==============================================================================
--- struts/shale/trunk/core-library/src/java/org/apache/shale/component/ValidatorScript.java (original)
+++ struts/shale/trunk/core-library/src/java/org/apache/shale/component/ValidatorScript.java Mon Apr 10 18:43:42 2006
@@ -17,16 +17,18 @@
 package org.apache.shale.component;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.StringTokenizer;
+import java.util.TreeSet;
 
 import javax.faces.component.EditableValueHolder;
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIComponentBase;
+import javax.faces.component.UIForm;
 import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
 import javax.faces.el.ValueBinding;
@@ -130,6 +132,51 @@
 
    }
 
+   /**
+    * <p>Restructures the validator hierarchy grouping by 
+    * form name, type and id.</p>
+    */
+   private Map getValidatorsGroupByFormName() {
+       Map formValidators = new LinkedHashMap();       
+       
+       Iterator vi = validators.entrySet().iterator();
+       while (vi.hasNext()) {
+          Map.Entry typeEntry = (Map.Entry) vi.next();
+          Map typeMap = (Map) typeEntry.getValue();
+          
+          String type = (String) typeEntry.getKey();
+          
+          Iterator ti = typeMap.entrySet().iterator();
+          while (ti.hasNext()) {
+             Map.Entry idEntry = (Map.Entry)ti.next();
+             String id = (String) idEntry.getKey();
+             CommonsValidator v = (CommonsValidator) idEntry.getValue();
+             String formName = v.getFormName();
+             
+             
+             Map formTypeMap = (Map) formValidators.get(formName);
+             if (formTypeMap == null) {
+                 formTypeMap = new LinkedHashMap();
+                 formValidators.put(formName, formTypeMap);
+             }
+             
+             Map formTypeIdMap = (Map) formTypeMap.get(type);
+             if (formTypeIdMap == null) {
+                 formTypeIdMap = new LinkedHashMap();
+                 formTypeMap.put(type, formTypeIdMap);
+             }
+             
+             formTypeIdMap.put(id, v);
+          }
+          
+          
+       }
+       
+       return formValidators;
+   }
+   
+   
+   
 
    /**
      * <p>Registers a validator according to type and id.
@@ -139,6 +186,7 @@
      * @param v The Commons validator associated with the id and type
      */
    private void addValidator(String type, String id, CommonsValidator v) {
+      // look for validators organized by type
       Map map = (Map) validators.get(type);
       if (map == null) {
          map = new LinkedHashMap();
@@ -165,6 +213,7 @@
          for (int i = 0; i < vs.length; i++) {
             if (vs[i] instanceof CommonsValidator) {
                CommonsValidator v = (CommonsValidator) vs[i];
+               v.setFormName(findForm(context, c));
                if (Boolean.TRUE.equals(v.getClient())) {
                    
                    //look for the clientId set 
@@ -250,21 +299,6 @@
      * <p>Returns the name of the JavaScript function, specified in
      *    the JSP page (presumably), that validates this JSP page's form.
      *
-     * @param action A Validator action
-     */
-   private static String getJavaScriptFunctionName(ValidatorAction action) {
-      StringTokenizer tokenizer = new StringTokenizer(
-         action.getJavascript(),
-         " \n\r\t(");
-      tokenizer.nextToken(); // function
-      return tokenizer.nextToken();
-   }
-
-
-    /**
-     * <p>Returns the name of the JavaScript function, specified in
-     *    the JSP page (presumably), that validates this JSP page's form.
-     *
      * @param writer A response writer
      * @param context The FacesContext for this request
      */
@@ -276,57 +310,122 @@
       writer.write("(form) { return bCancel || true\n");
       // for each validator type, write "&& fun(form);
 
-      Iterator iter = validators.keySet().iterator();
+      
+      Iterator iter = getTypesOrderedByDependencies(validators.keySet()).iterator();
       while (iter.hasNext()) {
          String type = (String) iter.next();
          ValidatorAction a = CommonsValidator.getValidatorAction(type);
          writer.write("&& ");
-         writer.write(getJavaScriptFunctionName(a));
+         writer.write(a.getJsFunctionName());
          writer.write("(form)\n");
       }
       writer.write(";}\n");
-
-      // for each validator type, write callback
-      iter = validators.keySet().iterator();
-      while (iter.hasNext()) {
-         String type = (String) iter.next();
-         ValidatorAction a = CommonsValidator.getValidatorAction(type);
-         writer.write("function " );
-         String callback = a.getJsFunctionName();
-         if (callback == null) callback = type;
-         writer.write(callback);
-         writer.write("() { \n");
-         // for each field validated by this type, add configuration object
-         Map map = (Map) validators.get(type);
-         Iterator iter2 = map.keySet().iterator();
-         int k = 0;
-         while (iter2.hasNext()) {
-            String id = (String) iter2.next();
-            CommonsValidator v = (CommonsValidator) map.get(id);
-            writer.write("this[" + k + "] = ");
-            k++;
-            writeJavaScriptParams(writer, context, id, v);
-            writer.write(";\n");
-         }
-         writer.write("}\n");         
+      
+      Map formValidators = getValidatorsGroupByFormName();
+      Iterator formIter = formValidators.entrySet().iterator();
+      while (formIter.hasNext()) {
+          Map.Entry typeEntry = (Map.Entry) formIter.next();
+          String formName = (String) typeEntry.getKey();
+          Map formTypeValidators = (Map) typeEntry.getValue();
+          
+          // for each validator type, write callback
+          
+          iter = formTypeValidators.keySet().iterator();
+          while (iter.hasNext()) {
+              String type = (String) iter.next();
+              ValidatorAction a = CommonsValidator.getValidatorAction(type);
+              writer.write("function " );
+              StringBuffer callback = new StringBuffer();
+              
+              // most of the type the callback function is based on the form name and 
+              // type but for some rules require special names
+              String fnameMnemonic = type;
+              if (type.equals("byte")) 
+                 fnameMnemonic = "ByteValidations";
+              else if (type.equals("short")) 
+                 fnameMnemonic = "ShortValidations";
+              else if (type.equals("integer")) 
+                 fnameMnemonic = "IntegerValidations";
+              else if (type.equals("float"))
+                  fnameMnemonic = "FloatValidations";
+              else if (type.equals("date"))
+                  fnameMnemonic = "DateValidations";
+               
+              
+              callback.append(formName).append('_').append(fnameMnemonic);
+              writer.write(callback.toString());
+              writer.write("() { \n");
+              // for each field validated by this type, add configuration object
+              Map map = (Map) formTypeValidators.get(type);
+              Iterator iter2 = map.keySet().iterator();
+              int k = 0;
+              while (iter2.hasNext()) {
+                  String id = (String) iter2.next();
+                  CommonsValidator v = (CommonsValidator) map.get(id);
+                  writer.write("this[" + k + "] = ");
+                  k++;
+                  writeJavaScriptParams(writer, context, id, v);
+                  writer.write(";\n");
+              }
+              writer.write("}\n");         
+          }
+          
       }
+      formValidators.clear();
 
-      // for each validator type, write code
-
-      // Must always include integer and required because
-      // they contain shared helper functions      
-      addValidator("integer", null, null);
-      addValidator("required", null, null);
-
-      iter = validators.keySet().iterator();
+      // resolve dependencies for a complete types list
+      
+      List types = new ArrayList(validators.keySet());
+      types.add("includeJavaScriptUtilities"); 
+            
+      iter = types.iterator();
       while (iter.hasNext()) {
          String type = (String) iter.next();
          ValidatorAction a = CommonsValidator.getValidatorAction(type);
          writer.write(a.getJavascript());
          writer.write("\n");
       }
+      
+      types.clear();
    }
 
+   
+   /**
+    * <p>Returns an array of validator types organized by dependencies.</p>
+    */
+   private List getTypesOrderedByDependencies(Set typeSet) {
+ 
+       List tmpList = new ArrayList(typeSet);
+       
+       ordered: for (int i = 0; i < tmpList.size(); i++) {
+           boolean swap = false; 
+           for (int j = 0; j < tmpList.size(); j++) {              
+               String type = (String) tmpList.get(j);
+               ValidatorAction a = CommonsValidator.getValidatorAction(type);
+               
+               List dependencies  = a.getDependencyList();
+               if (dependencies != null && dependencies.size() > 0) {
+                   int max = -1;
+                   for (int n = 0; n < dependencies.size(); n++) 
+                       max = Math.max(max, tmpList.indexOf(dependencies.get(n)));    
+                   if (max > j) {
+                       String tmp = (String) tmpList.get(j);
+                       tmpList.remove(j);
+                       tmpList.add(max, tmp);
+                       swap = true;
+                       j = max;
+                   }
+               }
+               
+           }   
+           if (!swap)
+             break ordered;
+       }
+       
+       return tmpList;
+       
+   }
+   
 
     /**
      * <p>Writes the JavaScript parameters for the client-side
@@ -334,10 +433,12 @@
      *
      * @param writer A response writer
      * @param context The FacesContext for this request
+     * @param id The clientId of the owning component
      * @param v The Commons validator
      */
    public void writeJavaScriptParams(ResponseWriter writer, 
-      FacesContext context, String id, CommonsValidator v) throws IOException {
+      FacesContext context, String id, CommonsValidator v) throws IOException {       
+ 
       writer.write("new Array(\"");
       writer.write(id);
       writer.write("\", \"");
@@ -361,6 +462,29 @@
       writer.write("}[x];\"))");
    }
 
+   
+   /**
+    * <p>Traverses up the tree looking for the owning form.  
+    * Returns the parent <code>UIForm</code> or empty string
+    * if one is not found.</p>
+    *  
+    * @param component <code>UIForm</code> parent of the component.
+    * @return
+    */
+   public String findForm(FacesContext context, UIComponent component) {
+    
+       UIComponent parent = null;
+
+       if ((parent = component.getParent()) != null) {
+          if (parent instanceof UIForm)  
+             return parent.getClientId(context);   
+          else
+             return findForm(context, parent);
+       }
+       
+       return "";
+   }
+   
 
     /**
      * <p>Begin encoding for this component. This method

Modified: struts/shale/trunk/core-library/src/java/org/apache/shale/taglib/ValidatorVarTag.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/java/org/apache/shale/taglib/ValidatorVarTag.java?rev=393130&r1=393129&r2=393130&view=diff
==============================================================================
--- struts/shale/trunk/core-library/src/java/org/apache/shale/taglib/ValidatorVarTag.java (original)
+++ struts/shale/trunk/core-library/src/java/org/apache/shale/taglib/ValidatorVarTag.java Mon Apr 10 18:43:42 2006
@@ -45,7 +45,7 @@
     * The value of the var to pass to the validator.
     */
    private String value;
-
+   
 
    /**
     * Keeps track of the &lt;s:commonsValidator&gt; tag.

Modified: struts/shale/trunk/core-library/src/java/org/apache/shale/validator/CommonsValidator.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/java/org/apache/shale/validator/CommonsValidator.java?rev=393130&r1=393129&r2=393130&view=diff
==============================================================================
--- struts/shale/trunk/core-library/src/java/org/apache/shale/validator/CommonsValidator.java (original)
+++ struts/shale/trunk/core-library/src/java/org/apache/shale/validator/CommonsValidator.java Mon Apr 10 18:43:42 2006
@@ -84,6 +84,25 @@
     private static final Log log = LogFactory.getLog(CommonsValidator.class);
     
 
+    /**
+     * <p>The name of the parent form used for javascript.</p>
+     */
+    public String formName = null;
+    
+    /**
+     * <p>Returns the parent's form name.</p>
+     */
+    public String getFormName() {
+       return formName;    
+    }
+    
+    /**
+     * <p>Sets the validator's owning form name.</p>
+     */
+    public void setFormName(String formName) {
+       this.formName = formName;    
+    }
+    
 
     // -------------------------------------------------------- Instance Variables
 
@@ -425,6 +444,7 @@
          if (maxlength != null) r.add("maxlength");
          if (mask != null) r.add("mask");
          if (datePatternStrict != null) r.add("datePatternStrict");
+         
          return (String[]) r.toArray(new String[r.size()]);
       }
       return (String[]) params.keySet()
@@ -527,9 +547,11 @@
          if (r.equals(Boolean.FALSE)) {
             Object errorValue = value;
 
-            if(component instanceof EditableValueHolder)
-               errorValue = ((EditableValueHolder)component)
-                                                 .getSubmittedValue();
+            if(component instanceof EditableValueHolder) {
+                errorValue = arg;    
+                //errorValue = ((EditableValueHolder)component)
+                //                              .getSubmittedValue();
+            }
 
             throw new ValidatorException(new FacesMessage(
                      FacesMessage.SEVERITY_ERROR, 

Modified: struts/shale/trunk/core-library/src/java/org/apache/shale/validator/messages.properties
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/java/org/apache/shale/validator/messages.properties?rev=393130&r1=393129&r2=393130&view=diff
==============================================================================
--- struts/shale/trunk/core-library/src/java/org/apache/shale/validator/messages.properties (original)
+++ struts/shale/trunk/core-library/src/java/org/apache/shale/validator/messages.properties Mon Apr 10 18:43:42 2006
@@ -14,3 +14,4 @@
 errors.range={0} is not in the range {1} through {2}.
 errors.creditcard={0} is an invalid credit card number.
 errors.email={0} is an invalid e-mail address.
+errors.url={0} is an invalid url address.

Modified: struts/shale/trunk/core-library/src/java/org/apache/shale/validator/messages_de.properties
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/java/org/apache/shale/validator/messages_de.properties?rev=393130&r1=393129&r2=393130&view=diff
==============================================================================
--- struts/shale/trunk/core-library/src/java/org/apache/shale/validator/messages_de.properties (original)
+++ struts/shale/trunk/core-library/src/java/org/apache/shale/validator/messages_de.properties Mon Apr 10 18:43:42 2006
@@ -14,3 +14,4 @@
 errors.range={0} liegt nicht zwischen {1} und {2}.
 errors.creditcard={0} ist keine g\u00FCltige Kreditkartenummer.
 errors.email={0} ist keine g\u00FCltige E-Mail-Adresse.
+errors.url={0} ist keine g\u00FCltige URL-Adresse.



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


Mime
View raw message