KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nemesis > forum > webapp > util > StrutsValidator


1
2 package org.nemesis.forum.webapp.util;
3
4 import javax.servlet.http.HttpServletRequest JavaDoc;
5
6 import org.apache.commons.validator.Field;
7 import org.apache.commons.validator.GenericValidator;
8 import org.apache.commons.validator.ValidatorAction;
9 import org.apache.commons.validator.ValidatorUtil;
10 import org.apache.struts.action.ActionErrors;
11 import org.apache.struts.validator.Resources;
12
13 /**
14  * @author dlaurent
15  *
16  * extra struts form validator
17  */

18 public class StrutsValidator {
19     
20     public static boolean validatePasswordFields(
21         Object JavaDoc bean,
22         ValidatorAction va,
23         Field field
24         ,ActionErrors errors,
25         HttpServletRequest JavaDoc request) {
26
27         String JavaDoc value = ValidatorUtil.getValueAsString(bean, field.getProperty());
28         String JavaDoc sProperty2 = field.getVarValue("secondProperty");
29         String JavaDoc value2 = ValidatorUtil.getValueAsString( bean, sProperty2);
30
31         if (!GenericValidator.isBlankOrNull(value)) {
32            try {
33               if (!value.equals(value2)) {
34                  errors.add(field.getKey(),
35                 Resources.getActionError(
36                         request,
37                         va,
38                         field));
39
40                  return false;
41               }
42            } catch (Exception JavaDoc e) {
43                  errors.add(field.getKey(),
44                 Resources.getActionError(
45                         request,
46                         va,
47                         field));
48                  return false;
49            }
50         }
51
52         return true;
53     }
54     
55     
56
57
58 }
59
Popular Tags