01 package com.bea.medrec.utils;
02
03 import org.apache.commons.validator.ValidatorAction;
04 import org.apache.commons.validator.Field;
05 import org.apache.commons.validator.GenericValidator;
06 import org.apache.struts.action.ActionErrors;
07 import org.apache.struts.validator.Resources;
08 import org.apache.commons.validator.ValidatorUtil;
09
10 import javax.servlet.http.HttpServletRequest;
11
12 /**
13 * <p>Used by web applications for field validation.</p>
14 */
15 public class StrutsValidator {
16 public static boolean validateTwoFields(
17 Object bean,
18 ValidatorAction va,
19 Field field,
20 ActionErrors errors,
21 HttpServletRequest request) {
22 String value = ValidatorUtil.getValueAsString(
23 bean,
24 field.getProperty());
25 String sProperty2 = field.getVarValue("secondProperty");
26 String value2 = ValidatorUtil.getValueAsString(
27 bean,
28 sProperty2);
29 if (!GenericValidator.isBlankOrNull(value)) {
30 try {
31 if (!value.equals(value2)) {
32 errors.add(field.getKey(),
33 Resources.getActionError(
34 request,
35 va,
36 field));
37
38 return false;
39 }
40 } catch (Exception e) {
41 errors.add(field.getKey(),
42 Resources.getActionError(
43 request,
44 va,
45 field));
46 return false;
47 }
48 }
49
50 return true;
51 }
52 }
|