[ 
https://issues.apache.org/jira/browse/WW-3827?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Lukasz Lenart updated WW-3827:
------------------------------

    Description: 
When you set up your validation.xml with short-circuit and use client-side 
validation by setting validate="true" in the s:form tag.

if one of the field has a short-circuited field-validator, the remaining 
generated javascript validations will be short-circuited as well.

For example, the following validation xml, if password has error, phone number 
will not be validate at all in the client-side.
{code:xml}
<field name="password">
    <field-validator type="requiredstring" short-circuit="true">
      <param name="trim">true</param>
      <message key="ERROR.REQUIRED_LOGIN_PASSWORD"/>
    </field-validator>
    <field-validator type="fieldexpression" short-circuit="true">
        <param name="expression">password==confirmPassword</param>
        <message key="ERROR.CONFIRM_PASSWORD"/>
    </field-validator>
    <field-validator type="stringlength">
      <param name="trim">true</param>
      <param name="minLength">6</param>
      <message key="ERROR.PASSWORD_TOO_SHORT"/>
    </field-validator>
  </field>
    
  <field name="phoneNumber">
    <field-validator type="requiredstring" short-circuit="true">
      <param name="trim">true</param>
      <message key="ERROR.REQUIRED_PHONE_NUMBER"/>
    </field-validator>
    <field-validator type="regex">
      <param name="trim">true</param>      
      <param name="expression"><![CDATA[^(\(?\d\d\d\)?)?( |-|\.)?\d\d\d( 
|-|\.)?\d{4,4}(( |-|\.)?[ext\.]+ ?\d+)?$]]></param>
      <message key="ERROR.INVALID_PHONE_NUMBER"/>
    </field-validator>
  </field>
{code}

This seems to be caused but the continueValidation flag in the 
form-close-validate.ftl freemarker template.

I've added a line in the template to reset the continueValidation flag at the 
start of each field:
... snip ...
{code:xml}
<#list parameters.tagNames as tagName>
        <#-- Fix issue with short-circuit one field-validator will 
short-circuit field-validators of other field name as well -->
        // field validators for tag, ${tagName}
        continueValidation = true;  // reset flag, as we are starting a new 
field name.
    
        <#list tag.getValidators("${tagName}") as validator>
{code}
... snip ...



  was:
When you set up your validation.xml with short-circuit and use client-side 
validation by setting validate="true" in the s:form tag.

if one of the field has a short-circuited field-validator, the remaining 
generated javascript validations will be short-circuited as well.

For example, the following validation xml, if password has error, phone number 
will not be validate at all in the client-side.
<field name="password">
    <field-validator type="requiredstring" short-circuit="true">
      <param name="trim">true</param>
      <message key="ERROR.REQUIRED_LOGIN_PASSWORD"/>
    </field-validator>
    <field-validator type="fieldexpression" short-circuit="true">
        <param name="expression">password==confirmPassword</param>
        <message key="ERROR.CONFIRM_PASSWORD"/>
    </field-validator>
    <field-validator type="stringlength">
      <param name="trim">true</param>
      <param name="minLength">6</param>
      <message key="ERROR.PASSWORD_TOO_SHORT"/>
    </field-validator>
  </field>
    
  <field name="phoneNumber">
    <field-validator type="requiredstring" short-circuit="true">
      <param name="trim">true</param>
      <message key="ERROR.REQUIRED_PHONE_NUMBER"/>
    </field-validator>
    <field-validator type="regex">
      <param name="trim">true</param>      
      <param name="expression"><![CDATA[^(\(?\d\d\d\)?)?( |-|\.)?\d\d\d( 
|-|\.)?\d{4,4}(( |-|\.)?[ext\.]+ ?\d+)?$]]></param>
      <message key="ERROR.INVALID_PHONE_NUMBER"/>
    </field-validator>
  </field>

This seems to be caused but the continueValidation flag in the 
form-close-validate.ftl freemarker template.

I've added a line in the template to reset the continueValidation flag at the 
start of each field:
... snip ...
<#list parameters.tagNames as tagName>
        <#-- Fix issue with short-circuit one field-validator will 
short-circuit field-validators of other field name as well -->
        // field validators for tag, ${tagName}
        continueValidation = true;  // reset flag, as we are starting a new 
field name.
    
        <#list tag.getValidators("${tagName}") as validator>
... snip ...



    
> Generated Javascript validation short-circuit one field, will short-circuit 
> all the remaining fields.
> -----------------------------------------------------------------------------------------------------
>
>                 Key: WW-3827
>                 URL: https://issues.apache.org/jira/browse/WW-3827
>             Project: Struts 2
>          Issue Type: Bug
>          Components: XML Validators
>    Affects Versions: 2.2.1, 2.3.3
>            Reporter: Jerome Chin
>             Fix For: 2.3.5
>
>         Attachments: form-close-validate.ftl
>
>
> When you set up your validation.xml with short-circuit and use client-side 
> validation by setting validate="true" in the s:form tag.
> if one of the field has a short-circuited field-validator, the remaining 
> generated javascript validations will be short-circuited as well.
> For example, the following validation xml, if password has error, phone 
> number will not be validate at all in the client-side.
> {code:xml}
> <field name="password">
>     <field-validator type="requiredstring" short-circuit="true">
>       <param name="trim">true</param>
>       <message key="ERROR.REQUIRED_LOGIN_PASSWORD"/>
>     </field-validator>
>     <field-validator type="fieldexpression" short-circuit="true">
>         <param name="expression">password==confirmPassword</param>
>         <message key="ERROR.CONFIRM_PASSWORD"/>
>     </field-validator>
>     <field-validator type="stringlength">
>       <param name="trim">true</param>
>       <param name="minLength">6</param>
>       <message key="ERROR.PASSWORD_TOO_SHORT"/>
>     </field-validator>
>   </field>
>     
>   <field name="phoneNumber">
>     <field-validator type="requiredstring" short-circuit="true">
>       <param name="trim">true</param>
>       <message key="ERROR.REQUIRED_PHONE_NUMBER"/>
>     </field-validator>
>     <field-validator type="regex">
>       <param name="trim">true</param>      
>       <param name="expression"><![CDATA[^(\(?\d\d\d\)?)?( |-|\.)?\d\d\d( 
> |-|\.)?\d{4,4}(( |-|\.)?[ext\.]+ ?\d+)?$]]></param>
>       <message key="ERROR.INVALID_PHONE_NUMBER"/>
>     </field-validator>
>   </field>
> {code}
> This seems to be caused but the continueValidation flag in the 
> form-close-validate.ftl freemarker template.
> I've added a line in the template to reset the continueValidation flag at the 
> start of each field:
> ... snip ...
> {code:xml}
> <#list parameters.tagNames as tagName>
>       <#-- Fix issue with short-circuit one field-validator will 
> short-circuit field-validators of other field name as well -->
>       // field validators for tag, ${tagName}
>       continueValidation = true;  // reset flag, as we are starting a new 
> field name.
>     
>         <#list tag.getValidators("${tagName}") as validator>
> {code}
> ... snip ...

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to