I am having a problem with the validator. It is not substituting the message with the correct values, null is being substituted instead. I am using Struts 1.1b.
I have a custom validator which checks that a phone number has a minimum number of digits (excluding special characters like spaces, plus signs, minus signs etc.) so I can't use the standard minlength validator. There are mask and maxlength validation rules on the field which are working perfectly. My custom validator is working perfectly (i.e. validating when it should and returning messages when it should), it is just the error message that is not working. Expected response when validation fails is: "Home Telephone Number must have at least 10 digits." instead, I am getting "Home Telephone Number must have at least null digits." Does anyone have any clues about this?? Thanks... Greg. properties file: errors.phoneNumber={0} must have at least {1} digits. validator-rules.xml: <validator name="phoneNumber" classname="com.jdv.stockhighway.web.validator.JDVWebValidator" method="validatePhoneNumber" methodParams="java.lang.Object, org.apache.commons.validator.ValidatorAction, org.apache.commons.validator.Field, org.apache.struts.action.ActionErrors, javax.servlet.http.HttpServletRequest" msg="errors.phoneNumber"> </validator> validation.xml: <field property="homeTelephoneNumber" depends="maxlength,mask,phoneNumber"> <arg0 key="errors.userDetailsForm.homeTelephoneNumber.prompt"/> <arg1 key="${var:maxlength}" name="maxlength" resource="false"/> <arg1 key="${var:mindigits}" name="mindigits" resource="false"/> <var> <var-name>mask</var-name> <var-value>^(\+|[0-9(][ -()]?)[0-9()]+([ -][0-9()]+)*$</var-value> </var> <var> <var-name>maxlength</var-name> <var-value>20</var-value> </var> <var> <var-name>mindigits</var-name> <var-value>10</var-value> </var> </field> custom validator: public static boolean validatePhoneNumber(Object bean, ValidatorAction va, Field field, ActionErrors errors, HttpServletRequest request) { String value = null; if (isString(bean)) { value = (String) bean; } else { value = ValidatorUtil.getValueAsString(bean, field.getProperty()); } if (value == null || value.equals("")) { return true; } int minDigits = Integer.parseInt(field.getVarValue("mindigits")); int digitCounter = 0; for (int i = 0; i < value.length(); i++) { if (value.charAt(i) >= '0' && value.charAt(i) <= '9') { digitCounter++; } } if (digitCounter >= minDigits) { return true; } else { errors.add(field.getKey(), StrutsValidatorUtil.getActionError(request, va, field)); return false; } } JDV - e-Commerce and Outsourcing Solutions for Financial Services http://www.jdv.com/ JDV is a division of Hartleys Limited ABN 67 009 136 029 ("JDV"). Any securities recommendation contained in this document is unsolicited general information only. Do not act on a recommendation without first consulting your investment advisor to determine whether the recommendation is appropriate for your investment objectives, financial situation and particular needs. JDV believes that any information or advice (including any securities recommendation) contained in this document is accurate when issued. However, JDV does not warrant its accuracy or reliability. JDV, its officers, agents and employees exclude all liability whatsoever, in negligence or otherwise, for any loss or damage relating to this document to the full extent permitted by law. JDV may collect personal information from you in order to provide any services you have requested. A copy of JDV's privacy policy is available at http://www.jdv.com/ -- To unsubscribe, e-mail: <mailto:struts-user-unsubscribe@;jakarta.apache.org> For additional commands, e-mail: <mailto:struts-user-help@;jakarta.apache.org>