Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Shale Wiki" for change 
notification.

The following page has been changed by WendySmoak:
http://wiki.apache.org/shale/ShaleValidation

The comment on the change is:
Update the instructions for custom validation rules.

------------------------------------------------------------------------------
  
  == Shale Commons Validator Integration ==
  
-  * http://struts.apache.org/struts-shale/features-commons-validator
+  * http://shale.apache.org/features-commons-validator
  
  === Validation error messages and the <s:validatorVar> tag ===
  
@@ -39, +39 @@

  
  To use a custom validation rule in your application, complete the following 
steps:
  
- '''1. Define an xml file conforming to the Commons Validator 1.2.0 dtd.'''
+ '''1. Define an xml file conforming to the Commons Validator 1.3.0 dtd.'''
  
  In this example, the file will be named 'custom-rules.xml' and will be placed 
in /WEB-INF.
  
  {{{
  <!DOCTYPE form-validation PUBLIC
-           "-//Apache Software Foundation//DTD Commons Validator Rules 
Configuration 1.2.0//EN"
+           "-//Apache Software Foundation//DTD Commons Validator Rules 
Configuration 1.3.0//EN"
-           "http://jakarta.apache.org/commons/dtds/validator_1_2_0.dtd";>
+           "http://jakarta.apache.org/commons/dtds/validator_1_3_0.dtd";>
  <form-validation>
     <global>
         <validator name="evenNumber"
@@ -56, +56 @@

               msg="errors.even">
         </validator>
     </global>
+ 
+    <formset>
+       <form name="org.apache.shale.validator.evenInteger">
+           <field property="evenInteger">
+ 
+               <!-- validation error message replacement parameters -->
+               <arg position="0" name="message" key="submittedValue" 
resource="false"/>
+ 
+               <!-- validation method parameters -->
+               <arg position="0" name="parameter" key="submittedValue" 
resource="false"/>
+ 
+           </field>
+         </form>
+     </formset>
+ 
  </form-validation>
  }}}
  
@@ -86, +101 @@

      </context-param>
  }}}
  
- !CommonsValidator will pass the value entered by the user as the first 
parameter of your validation method, provided you have listed at least one type 
in the 'methodParams' attribute of your <validator> tag.
- 
- In addition, if you add them as attributes to the <s:commonsValidator> tag, 
!CommonsValidator will pass the following parameters through to your validation 
method:  min, max, minlength, maxlength, mask, and datePatternStrict.  These 
parameters are always passed in exactly this order, no matter how they are 
listed in <s:commonsValidator>.
- 
  '''4. Provide a resource bundle for messages.''' (Optional)
  
- The !CommonsValidator class reads the messages from the application's 
resource bundle, then from the 'messages' bundle in org.apache.struts.validator 
(the (localized) messages.properties file inside shale-core.jar).
+ The !CommonsValidator class reads the messages from the application's 
resource bundle, then from the 'messages' bundle in org.apache.shale.validator 
(the (localized) messages.properties file inside shale-core.jar).
  
  If you can use one of the provided messages for your validator, then no 
action is necessary.
  
@@ -115, +126 @@

  {{{
       errors.even={0} is not an even number.
  }}}
- 
- The value of the field being validated is automatically passed as {0} for 
message parameter replacement.
  
  '''5. Attach your new validation rule to a component.'''
  
@@ -157, +166 @@

    </h:form>
  }}}
  
- === Using Rules With Multiple Parameters ===
- 
- The following example demonstrates the use of all of the attributes accepted 
by the <s:commonsValidator> tag, though it's unlikely that a single validator 
would make use of all six method parameters:  min, max, minlength, maxlength, 
mask and datePatternStrict.
- 
- Numbered as above:
- 
- '''1.'''
- {{{
-        <validator name="allParams"
-              classname="com.example.ValidationUtil"
-              method="isValid"
-              
methodParams="java.lang.String,double,double,int,int,java.lang.String,java.lang.String"
-              msg="errors.all">
-        </validator>
- }}}
- 
- '''2.'''
- {{{
-     public static boolean isValid( String value, double min, double max, int 
minlength, int maxlength,
-                                    String mask, String datePatternStrict) {
-         return false;
-     }
- }}}
- 
- The attributes will be passed as parameters to your validation method in 
exactly this order, though most validators will only use a subset of the 
available attributes.
- 
- '''4.'''
- {{{
- errors.all={0} must be at least {1}, not more than {2}, between {3} and {4} 
in length, and conform to mask {5} and date pattern {6}.  Good luck!
- }}}
- 
- '''5.'''
- {{{
-             <s:commonsValidator
-                      type="allParams"
-                    server="true"
-                    client="false"
-                       max="5.7"
-                 minlength="2"
-                       min="1.2"
-                 maxlength="6"
-                      mask="[4-6].*"
-         datePatternStrict="MM/dd/yyyy" />
- }}}
- 
- Note that this will ''always'' fail because the 'isValid' method returns 
false.
- 
  === Required Validator ===
  
  The 'required' validator is a special case.  The JSF framework will only call 
a Validator if a value was submitted.  Usually, you would set required="true" 
as an attribute on the input component.
@@ -227, +189 @@

  
  === References ===
  
-  * http://struts.apache.org/struts-shale/features-commons-validator.html
+  * http://shale.apache.org/features-commons-validator.html
-   * 
[http://struts.apache.org/struts-shale/shale-core/apidocs/org/apache/shale/validator/CommonsValidator.html
 CommonsValidator API]
+   * 
[http://shale.apache.org/shale-core/apidocs/org/apache/shale/validator/CommonsValidator.html
 CommonsValidator API]
-   * 
[http://struts.apache.org/struts-shale/shale-core/apidocs/org/apache/shale/component/ValidatorScript.html
 ValidatorScript API]
+   * 
[http://shale.apache.org/shale-core/apidocs/org/apache/shale/component/ValidatorScript.html
 ValidatorScript API]
  
   * http://jakarta.apache.org/commons/validator/
    * 
[http://jakarta.apache.org/commons/validator/api-1.2.0/org/apache/commons/validator/ValidatorResources.html
 ValidatorResources API]
@@ -246, +208 @@

   * [http://issues.apache.org/bugzilla/show_bug.cgi?id=38044 Bug 38044] - The 
filename and location of validator rules files are configurable (Since 1.0.1).
  
  -----
- ''Please address questions about Shale's Commons Validator integration to the 
[http://struts.apache.org/mail.html struts-user] list.'''
+ ''Please address questions about Shale's Commons Validator integration to the 
[http://shale.apache.org/mail-lists.html shale-user] list.'''
  

Reply via email to