1 package org.appfuse.webapp.util; 2 3 import javax.servlet.http.HttpServletRequest ; 4 5 import org.apache.commons.validator.Field; 6 import org.apache.commons.validator.GenericValidator; 7 import org.apache.commons.validator.ValidatorAction; 8 import org.apache.commons.validator.util.ValidatorUtils; 9 import org.apache.struts.action.ActionMessages; 10 import org.apache.struts.validator.Resources; 11 12 13 24 public class ValidationUtil { 25 27 36 public static boolean validateTwoFields(Object bean, ValidatorAction va, 37 Field field, ActionMessages errors, 38 HttpServletRequest request) { 39 String value = 40 ValidatorUtils.getValueAsString(bean, field.getProperty()); 41 String sProperty2 = field.getVarValue("secondProperty"); 42 String value2 = ValidatorUtils.getValueAsString(bean, sProperty2); 43 44 if (!GenericValidator.isBlankOrNull(value)) { 45 try { 46 if (!value.equals(value2)) { 47 errors.add(field.getKey(), 48 Resources.getActionMessage(request, va, field)); 49 50 return false; 51 } 52 } catch (Exception e) { 53 errors.add(field.getKey(), 54 Resources.getActionMessage(request, va, field)); 55 56 return false; 57 } 58 } 59 60 return true; 61 } 62 } 63 | Popular Tags |