dwinterfeldt 01/10/18 15:06:32
Modified: contrib/validator/src/share/com/wintecinc/struts/validation
StrutsValidator.java
Log:
Added a check for validateMinLength and validateMaxLength to see if value isn't
null. If it is null the validation is skipped. This is consitant with the other
validation methods.
Revision Changes Path
1.4 +20 -18
jakarta-struts/contrib/validator/src/share/com/wintecinc/struts/validation/StrutsValidator.java
Index: StrutsValidator.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/contrib/validator/src/share/com/wintecinc/struts/validation/StrutsValidator.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- StrutsValidator.java 2001/10/17 20:16:06 1.3
+++ StrutsValidator.java 2001/10/18 22:06:32 1.4
@@ -479,18 +479,19 @@
String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
String sMaxLength = field.getVarValue("maxlength");
- // NullPointerException could occur, but it will be treated as failing the
validation
- try {
- int max = Integer.parseInt(sMaxLength);
-
- if (!GenericValidator.maxLength(value, max)) {
- errors.add(field.getKey(), ValidatorUtil.getActionError(application,
request, va, field));
+ if (value != null) {
+ try {
+ int max = Integer.parseInt(sMaxLength);
+ if (!GenericValidator.maxLength(value, max)) {
+ errors.add(field.getKey(),
ValidatorUtil.getActionError(application, request, va, field));
+
+ return false;
+ }
+ } catch (Exception e) {
+ errors.add(field.getKey(), ValidatorUtil.getActionError(application,
request, va, field));
return false;
}
- } catch (Exception e) {
- errors.add(field.getKey(), ValidatorUtil.getActionError(application,
request, va, field));
- return false;
}
return true;
@@ -518,18 +519,19 @@
String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
String sMinLength = field.getVarValue("minlength");
- // NullPointerException could occur, but it will be treated as failing the
validation
- try {
- int min = Integer.parseInt(sMinLength);
-
- if (!GenericValidator.minLength(value, min)) {
- errors.add(field.getKey(), ValidatorUtil.getActionError(application,
request, va, field));
+ if (value != null) {
+ try {
+ int min = Integer.parseInt(sMinLength);
+ if (!GenericValidator.minLength(value, min)) {
+ errors.add(field.getKey(),
ValidatorUtil.getActionError(application, request, va, field));
+
+ return false;
+ }
+ } catch (Exception e) {
+ errors.add(field.getKey(), ValidatorUtil.getActionError(application,
request, va, field));
return false;
}
- } catch (Exception e) {
- errors.add(field.getKey(), ValidatorUtil.getActionError(application,
request, va, field));
- return false;
}
return true;