You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by Apache Wiki <wi...@apache.org> on 2006/07/31 11:18:05 UTC

[Struts Wiki] Update of "Shale/Validation" by ReneZanner

Dear Wiki user,

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

The following page has been changed by ReneZanner:
http://wiki.apache.org/struts/Shale/Validation

The comment on the change is:
added remark for wizard-style back navigation using commandButton

------------------------------------------------------------------------------
  
  === Validation error messages and the <s:validatorVar> tag ===
  
- The parameters used to format the [http://svn.apache.org/repos/asf/struts/shale/trunk/core-library/src/java/org/apache/shale/validator/messages.properties error messages] that are shown when a validation error occurs include the incorrect value and any validator-specific 'var' parameters.  
+ The parameters used to format the [http://svn.apache.org/repos/asf/struts/shale/trunk/core-library/src/java/org/apache/shale/validator/messages.properties error messages] that are shown when a validation error occurs include the incorrect value and any validator-specific 'var' parameters.
  
  When the <s:validatorVar> tag is used for validator-specific 'var' parameters, the order in which the 'var's are declared is the order that will be used to format the error message.
  
@@ -24, +24 @@

  {{{
  <s:commonsValidator type="floatRange"
                       arg="#{msgs.amount}"
-                   server="true" 
+                   server="true"
                    client="false">
      <s:validatorVar name="min" value="10"/>
      <s:validatorVar name="max" value="1000"/>
@@ -63, +63 @@

  public class ValidationUtil implements Serializable
  {
      public static boolean isEven( int value ) {
-        return (value % 2 == 0);    
+        return (value % 2 == 0);
      }
  }
  }}}
  
- '''3. Configure the validation rules in web.xml.''' 
+ '''3. Configure the validation rules in web.xml.'''
  
  Include the default rule set by listing "/org/apache/shale/validator/validator-rules.xml" in addition to your custom rules.
  
@@ -142, +142 @@

    </h:form>
  }}}
  
+ '''ATTENTION:''' When using commandButton with immediate="true" for wizard-style "back" navigation, be sure to remove the "onsubmit" handler from the form and attach it to the normal "next" commandButton ("onclick" handler) instead. Otherwise the client-side validation will be executed even in the "back" navigation case.
+ 
+ {{{
+   <h:form>
+      ...
+      <h:commandButton action="back" immediate="true" ... />
+      <h:commandButton action="#{wizard.gotoPage2}" onclick="return validateForm(this.form);" ... />
+      <s:validatorScript functionName="validateForm"/>
+   </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.  
+ 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:
  
@@ -191, +202 @@

  
  === 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.  
+ 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.
  
  So that you don't have to remember to do something different for 'required', Shale allows <s:validator type="required">, which works by setting the required attribute of the surrounding input component to true.
  
@@ -203, +214 @@

           methodParams="java.lang.String"
                    msg="errors.required">
           <javascript>...</javascript>
-       </validator>        
+       </validator>
  }}}
  
  However, neither the 'isSupplied' method in !CommonsValidator, nor the 'errors.required' message is ever used.