1 2 package org.nemesis.forum.webapp.util; 3 4 import javax.servlet.http.HttpServletRequest ; 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 18 public class StrutsValidator { 19 20 public static boolean validatePasswordFields( 21 Object bean, 22 ValidatorAction va, 23 Field field 24 ,ActionErrors errors, 25 HttpServletRequest request) { 26 27 String value = ValidatorUtil.getValueAsString(bean, field.getProperty()); 28 String sProperty2 = field.getVarValue("secondProperty"); 29 String 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 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 |