[ http://issues.apache.org/struts/browse/STR-2854?page=all ] Jorge Rodríguez closed STR-2854: --------------------------------
Thanks for your help, I Hope see this change included in the next release. > 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 > Assignee: Don Brown > Priority: Critical > Fix For: 1.3.3 > > 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 string with a date format > (dd/mm/yyyy), so, i need to check it (optional fields with a special format. > For that reason, I can't use the "required" rule). The problem is when it is > filled in with only blank spaces. In this case, the "mask" validator doesn't > work. > <field property="txtDate" 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>${formatDate}</var-value> > </var> > <var> > <var-name>test</var-name> > <var-value>(((rdSelector==0) and (*this* !=null )) or > (rdSelector==1))</var-value> > </var> > </field> > where: > ${formatDate} = ^[0-9][0-9][/][0-9][0-9][/][0-9][0-9][0-9][0-9]$ > rdSelector is my radio button field > txtDate is a date 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 condition > never executes because of the && operator, so, the Regular expression is > never checked.. > I think , the if statement should be something like this ... > if (value != null && value.length()>0 > && !GenericValidator.matchRegexp(value, mask)) { > > it is almost the same as the original if, but the difference is that it also > includes strings with only > blank spaces, and in this case the validator returns false just as it > should be .. > have you seen any problem like this?, can be fixed this problem in new > releases? or there are some other solutions to solve it ? > > 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
