1 27 package olstore.validation; 28 29 30 import java.io.Serializable; 31 import javax.servlet.http.HttpServletRequest; 32 import org.apache.commons.validator.Field; 33 import org.apache.commons.validator.GenericValidator; 34 import org.apache.commons.validator.ValidatorAction; 35 import org.apache.commons.validator.ValidatorUtil; 36 import org.apache.struts.action.ActionMessages; 37 import org.apache.struts.validator.Resources; 38 39 public class Validator implements Serializable { 40 41 42 49 public static boolean validateTwoFields( 50 Object bean, 51 ValidatorAction va, 52 Field field, 53 ActionMessages errors, 54 org.apache.commons.validator.Validator validator, 55 HttpServletRequest request) { 56 57 String value = ValidatorUtil.getValueAsString( 58 bean, 59 field.getProperty()); 60 String sProperty2 = field.getVarValue("secondProperty"); 61 String value2 = ValidatorUtil.getValueAsString( 62 bean, 63 sProperty2); 64 65 if (!GenericValidator.isBlankOrNull(value)) { 66 try { 67 if (!value.equals(value2)) { 68 errors.add(field.getKey(), 69 Resources.getActionError(request,va,field)); 70 71 return false; 72 } 73 } catch (Exception e) { 74 errors.add(field.getKey(), 75 Resources.getActionError(request, va,field)); 76 return false; 77 } 78 } 79 80 return true; 81 } 82 83 } 84 | Popular Tags |