struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jorge Rodríguez (JIRA) <j...@apache.org>
Subject [jira] Created: (STR-2854) mask validator error
Date Tue, 02 May 2006 22:31:21 GMT
mask validator error
--------------------

         Key: STR-2854
         URL: http://issues.apache.org/struts/browse/STR-2854
     Project: Struts Action 1
        Type: Bug

  Components: Core  
    Versions: 1.2.7    
 Environment: Windows XP, Weblogic 8.1 SP5
    Reporter: Jorge Rodríguez
    Priority: Critical


I have a problem with the mask validator when it is used without  others validators such as
"required"  in struts 1.2.7. 
For example,  I have a field which  depends of a radio button selecction (requiredif in previous
versions). In this case I'm using the "validwhen" and the "mask" validators because that field
is  an integer data type, so, i need to check it.  The problem is when it is filled in with
only blank spaces. In this case, the "mask" validator doesn't work. 

<field property="txtAnio" depends="mask,validwhen">
   <msg name="mask" key="errors.invalid"/>
        <arg position="0" key="Año" resource="false"/>
             <var>
                 <var-name>mask</var-name>
                 <var-value>${numeros}</var-value>
             </var>
        <var>
           <var-name>test</var-name>
           <var-value>(((rdSelector==0) and (*this* >0 )) or (rdSelector==1))</var-value>
        </var>
  </field>
where:
${numeros} = ^[0-9]*$
rdSelector is my radio  button  field
txtAnio is a year textfield.

I think, the problem is in the validateMask method of the FieldChecks class (org.apache.struts.validator):

public static boolean validateMask(Object bean,ValidatorAction va, Field field,ActionMessages
errors, Validator validator, HttpServletRequest request) {

        String mask = field.getVarValue("mask");
        String value = null;
        if (isString(bean)) {
            value = (String) bean;
        } else {
            value = ValidatorUtils.getValueAsString(bean, field.getProperty());
        }
        try {
            if (!GenericValidator.isBlankOrNull(value) // <b>THIS IS THE PROBLEM</b>
                && !GenericValidator.matchRegexp(value, mask)) {
                errors.add(field.getKey(),
                    Resources.getActionMessage(validator, request, va, field));
                return false;
            } else {
                return true;
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        return true;
    }

The problem I found is in the second if:   
 if (!GenericValidator.isBlankOrNull(value)  && ......

this means that if the field is empty, null or with only blank spaces as the isBlankOrNull
method  does, 
the  field is not considered as invalid (the if block  doesn't execute, so no errors are generated)
and the second part of that  if never executes because of the && operator so, the
Regular expression  is never checked.. so it is almost right, but  fails with blank spaces
..

do you have any options to solve it ?,  
Ineed to change the struts.jar ?,  I checked the same class in struts 1.2.9 and the problem
remains.

Thanks for your help ..

		  



-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/struts/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


Mime
View raw message