List of usage examples for org.apache.commons.validator Field getKey
public String getKey()
From source file:jp.terasoluna.fw.web.struts.form.FieldChecksEx.java
/** * ?tB?[h`FbN?s?B//from w w w . j a v a 2s. co m * * ??[?s{@link MultiFieldValidator} NX Kv?BNX * <code>validation.xml</code> ??s?B<br> * G?[???AG?[????A wG?[?Xg?B ??[ftHgG?[?bZ?[W?A * ?bZ?[W <code>validation.xml</code> KL?q?B<br> * ANVtH?[valuetB?[hl?Avalue1tB?[hl??A * value2tB?[hl????A?A ??s?B * <h5>{@link MultiFieldValidator} </h5> * <code><pre> * public boolean validate(String value, String[] depends) { * int value0 = Integer.parseInt(value); * int value1 = Integer.parseInt(depends[0]); * int value2 = Integer.parseInt(depends[1]); * return (value1 <= value0 && value2 >= value0); * } * </pre></code> * <h5>validation.xml?</h5> * <code><pre> * <form name="/validateMultiField"> * <field property="value" depends="multiField"> * <msg key="errors.multiField" * name="multiField"/> * <arg key="label.value" position="0" /> * <arg key="label.value1" position="1" /> * <arg key="label.value2" position="2" /> * <var> * <var-name>fields</var-name> * <var-value>value1,value2</var-value> * </var> * <var> * <var-name>multiFieldValidator</var-name> * <var-value>sample.SampleMultiFieldValidator</var-value> * </var> * </field> * </form> * </pre></code> * <h5>?bZ?[W\?[Xt@C?</h5> * <code> * errors.multiField={0}{1}{2}l?B * </code> * * <h5>validation.xml?v<var>vf</h5> * <table border="1"> * <tr> * <td><center><b><code>var-name</code></b></center></td> * <td><center><b><code>var-value</code></b></center></td> * <td><center><b>K?{?</b></center></td> * <td><center><b>Tv</b></center></td> * </tr> * <tr> * <td> fields </td> * <td>?KvtB?[h</td> * <td>false</td> * <td>?tB?[hw??tB?[hJ}? w?B</td> * </tr> * <tr> * <td> multiFieldValidator </td> * <td>{@link MultiFieldValidator} NX</td> * <td>false</td> * <td>?tB?[h`FbN?s {@link MultiFieldValidator} NX?B</td> * </tr> * </table> * * @param bean * ??IuWFNg * @param va * ValidatorpValidatorAction * @param field * tB?[hIuWFNg * @param errors * ANVG?[ * @param validator * ValidatorCX^X * @param request * HTTPNGXg * @return l? <code>true</code> */ public static boolean validateMultiField(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request) { // beannull?AG?[?O?o?Atruep?B if (bean == null) { log.error("bean is null."); return true; } // ??l String value = null; if (isString(bean)) { value = (String) bean; } else { value = ValidatorUtils.getValueAsString(bean, field.getProperty()); } // tB?[hK?{`FbN?l?A // ?lnull???tB?[h`FbN?s?B // MultiFieldValidatorNX String multiFieldValidatorClass = field.getVarValue("multiFieldValidator"); if (multiFieldValidatorClass == null || "".equals(multiFieldValidatorClass)) { log.error("var value[multiFieldValidator] is required."); throw new IllegalArgumentException("var value[multiFieldValidator] is required."); } MultiFieldValidator mfv = null; try { mfv = (MultiFieldValidator) ClassUtil.create(multiFieldValidatorClass); } catch (ClassLoadException e) { log.error("var value[multiFieldValidator] is invalid.", e); throw new IllegalArgumentException("var value[multiFieldValidator] is invalid.", e); } catch (ClassCastException e) { log.error("var value[multiFieldValidator] is invalid.", e); throw new IllegalArgumentException("var value[multiFieldValidator] is invalid.", e); } // ?tB?[hl String fields = field.getVarValue("fields"); List<String> valueList = new ArrayList<String>(); if (fields != null) { StringTokenizer st = new StringTokenizer(fields, ","); while (st.hasMoreTokens()) { String f = st.nextToken(); f = f.trim(); valueList.add(ValidatorUtils.getValueAsString(bean, f)); } } if (log.isDebugEnabled()) { log.debug("dependent fields:" + valueList); } String[] values = new String[valueList.size()]; valueList.toArray(values); boolean result = mfv.validate(value, values); if (!result) { errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field)); return false; } return true; }
From source file:net.naijatek.myalumni.framework.struts.MyAlumniValidator.java
/** * Compares both the password and confirmation password to_email be the same * //from w w w .j a va 2 s. c o m * @param bean * Object * @param va * ValidatorAction * @param field * Field * @param messages * ActionMessages * @param request * HttpServletRequest * @return boolean */ public boolean searchCategory(Object bean, ValidatorAction va, Field field, ActionMessages messages, HttpServletRequest request) { boolean condition = true; MemberForm memForm = (MemberForm) bean; String searchCategory = StringUtil.safeString(memForm.getSearchCategory()); String userName = StringUtil.safeString(memForm.getMemberUserName()); String firstName = StringUtil.safeString(memForm.getFirstName()); String lastName = StringUtil.safeString(memForm.getLastName()); String dorm = StringUtil.safeString(memForm.getDormitoryId()); String gender = StringUtil.safeString(memForm.getGender()); String yearIn = StringUtil.safeString(memForm.getYearIn()); String yearOut = StringUtil.safeString(memForm.getYearOut()); String marriageName = StringUtil.safeString(memForm.getLastName()); String nickName = StringUtil.safeString(memForm.getNickName()); String maidenName = StringUtil.safeString(memForm.getMaidenName()); if (searchCategory.equalsIgnoreCase(BaseConstants.FULL_SEARCH)) { if (firstName.length() == 0 && lastName.length() == 0 && dorm.length() == 0 && gender.length() == 0 && yearIn.length() == 0 && yearOut.length() == 0 && marriageName.length() == 0 && nickName.length() == 0/* * && * maidenName.length() == * 0 */) { condition = false; } } else if (searchCategory.equalsIgnoreCase(BaseConstants.FIRST_NAME)) { if (firstName.length() == 0) { condition = false; } } else if (searchCategory.equalsIgnoreCase(BaseConstants.USERNAME)) { if (userName.length() == 0) { condition = false; } } else if (searchCategory.equalsIgnoreCase(BaseConstants.LAST_NAME)) { if (lastName.length() == 0) { condition = false; } } else if (searchCategory.equalsIgnoreCase(BaseConstants.DORMITORY)) { if (dorm.length() == 0) { condition = false; } } else if (searchCategory.equalsIgnoreCase(BaseConstants.YEAR_IN)) { if (yearIn.length() == 0) { condition = false; } } else if (searchCategory.equalsIgnoreCase(BaseConstants.YEAR_OUT)) { if (yearOut.length() == 0) { condition = false; } } else if (searchCategory.equalsIgnoreCase(BaseConstants.NICK_NAME)) { if (nickName.length() == 0) { condition = false; } } else if (searchCategory.equalsIgnoreCase(BaseConstants.MARRIED_NAME)) { if (marriageName.length() == 0) { condition = false; } } else if (searchCategory.equalsIgnoreCase(BaseConstants.MAIDEN_NAME)) { if (maidenName.length() == 0) { condition = false; } } else if (searchCategory.equalsIgnoreCase(BaseConstants.GENDER)) { if (gender.length() == 0) { condition = false; } } if (!condition) { messages.add(field.getKey(), Resources.getActionMessage(request, va, field)); } return messages.isEmpty(); }
From source file:jp.terasoluna.fw.validation.FieldChecks.java
/** * ????????//from w w w. j a v a 2 s. c o m * ??????????errors??? * false?? * * <p>?????????? * ?????????validation.xml? * ??depends????Array??????? * depends="requiredArray" "required" ? * * @param bean ?JavaBean * @param va Validator????ValidatorAction * @param field * @param errors * @return ????????? true * @throws ValidatorException validation?????? * ???bean?null????? */ public boolean validateArraysIndex(Object bean, ValidatorAction va, Field field, ValidationErrors errors) throws ValidatorException { if (bean == null) { log.error("validation target bean is null."); throw new ValidatorException("validation target bean is null."); } @SuppressWarnings("rawtypes") Class[] paramClass = null; // ?? Method method = null; // try { paramClass = getParamClass(va); if (paramClass == null || paramClass.length == 0) { String message = "Mistake on validation rule file. " + "- Can not get argument class. " + "You'll have to check it over. "; log.error(message); throw new ValidatorException(message); } method = getMethod(va, paramClass); if (method == null) { String message = "Mistake on validation rule file. " + "- Can not get validateMethod. " + "You'll have to check it over. "; log.error(message); throw new ValidatorException(message); } } catch (RuntimeException e) { log.error(e.getMessage(), e); throw new ValidatorException(e.getMessage()); } try { // ??????????? Object[] argParams = new Object[paramClass.length]; argParams[0] = bean; argParams[1] = va; argParams[3] = errors; // ????? IndexedBeanWrapper bw = getIndexedBeanWrapper(bean); Map<String, Object> propertyMap = bw.getIndexedPropertyValues(field.getKey()); boolean isValid = true; // for (String key : propertyMap.keySet()) { // ?????????? Field indexedField = (Field) field.clone(); indexedField.setKey(key); indexedField.setProperty(key); argParams[2] = indexedField; // // ???? boolean bool = (Boolean) method.invoke(this, argParams); if (!bool) { isValid = false; } } return isValid; } catch (InvocationTargetException e) { Throwable t = e.getTargetException(); if (t instanceof ValidatorException) { throw (ValidatorException) t; } log.error(t.getMessage(), t); throw new ValidatorException(t.getMessage()); } catch (Exception e) { log.error(e.getMessage(), e); throw new ValidatorException(e.getMessage()); } }
From source file:org.apache.beehive.netui.pageflow.validation.ValidatorRules.java
/** * Check if a given expression evaluates to <code>true</code>. * /* www . j a v a 2s .c o m*/ * @param bean the bean that validation is being performed on. * @param va the <code>ValidatorAction</code> that is currently being performed. * @param field the <code>Field</code> object associated with the current field being validated. * @param errors the <code>ActionMessages</code> object to add errors to if any validation errors occur. * @param request the current request object. * @return <code>true</code> if the given expression evaluates to <code>true</code> */ public static boolean validateValidWhen(Object bean, ValidatorAction va, Field field, ActionMessages errors, HttpServletRequest request, ServletContext servletContext) { String value; if (isString(bean)) { value = (String) bean; } else { value = ValidatorUtil.getValueAsString(bean, field.getProperty()); } if (!GenericValidator.isBlankOrNull(value)) { String condition = field.getVarValue("netui_validwhen"); try { if (!InternalExpressionUtils.evaluateCondition(condition, bean, request, servletContext)) { errors.add(field.getKey(), Resources.getActionError(request, va, field)); return false; } } catch (Exception e) { _log.error("Error evaluating expression " + condition + " for ValidWhen rule on field " + field.getProperty() + " on bean of type " + (bean != null ? bean.getClass().getName() : null)); errors.add(field.getKey(), Resources.getActionError(request, va, field)); return false; } } return true; }
From source file:org.apache.beehive.netui.pageflow.validation.ValidatorRules.java
/** * Check if a field's value is within a range ("min" and "max" Long variables on the passed-in Field). * * @param bean the bean that validation is being performed on. * @param va the <code>ValidatorAction</code> that is currently being performed. * @param field the <code>Field</code> object associated with the current field being validated. * @param errors the <code>ActionMessages</code> object to add errors to if any validation errors occur. * @param request the current request object. * @return <code>true</code> if in range, false otherwise. *//*from w ww .ja v a 2s. c o m*/ public static boolean validateLongRange(Object bean, ValidatorAction va, Field field, ActionMessages errors, HttpServletRequest request) { String value; if (isString(bean)) { value = (String) bean; } else { value = ValidatorUtil.getValueAsString(bean, field.getProperty()); } if (!GenericValidator.isBlankOrNull(value)) { try { long longValue = Long.parseLong(value); long min = Long.parseLong(field.getVarValue("min")); long max = Long.parseLong(field.getVarValue("max")); if (longValue < min || longValue > max) { errors.add(field.getKey(), Resources.getActionError(request, va, field)); return false; } } catch (Exception e) { errors.add(field.getKey(), Resources.getActionError(request, va, field)); return false; } } return true; }
From source file:org.apache.struts.faces.taglib.JavascriptValidatorTag.java
/** * Render the JavaScript for to perform validations based on the form name. * * @exception JspException if a JSP exception has occurred */// w ww . jav a2s. c om public int doStartTag() throws JspException { StringBuffer results = new StringBuffer(); ModuleConfig config = RequestUtils.getModuleConfig(pageContext); ValidatorResources resources = (ValidatorResources) pageContext .getAttribute(ValidatorPlugIn.VALIDATOR_KEY + config.getPrefix(), PageContext.APPLICATION_SCOPE); Locale locale = RequestUtils.retrieveUserLocale(this.pageContext, null); Form form = resources.get(locale, formName); if (form != null) { if ("true".equalsIgnoreCase(dynamicJavascript)) { MessageResources messages = (MessageResources) pageContext.getAttribute(bundle + config.getPrefix(), PageContext.APPLICATION_SCOPE); List lActions = new ArrayList(); List lActionMethods = new ArrayList(); // Get List of actions for this Form for (Iterator i = form.getFields().iterator(); i.hasNext();) { Field field = (Field) i.next(); for (Iterator x = field.getDependencies().iterator(); x.hasNext();) { Object o = x.next(); if (o != null && !lActionMethods.contains(o)) { lActionMethods.add(o); } } } // Create list of ValidatorActions based on lActionMethods for (Iterator i = lActionMethods.iterator(); i.hasNext();) { String depends = (String) i.next(); ValidatorAction va = resources.getValidatorAction(depends); // throw nicer NPE for easier debugging if (va == null) { throw new NullPointerException( "Depends string \"" + depends + "\" was not found in validator-rules.xml."); } String javascript = va.getJavascript(); if (javascript != null && javascript.length() > 0) { lActions.add(va); } else { i.remove(); } } Collections.sort(lActions, new Comparator() { public int compare(Object o1, Object o2) { ValidatorAction va1 = (ValidatorAction) o1; ValidatorAction va2 = (ValidatorAction) o2; if ((va1.getDepends() == null || va1.getDepends().length() == 0) && (va2.getDepends() == null || va2.getDepends().length() == 0)) { return 0; } else if ((va1.getDepends() != null && va1.getDepends().length() > 0) && (va2.getDepends() == null || va2.getDepends().length() == 0)) { return 1; } else if ((va1.getDepends() == null || va1.getDepends().length() == 0) && (va2.getDepends() != null && va2.getDepends().length() > 0)) { return -1; } else { return va1.getDependencies().size() - va2.getDependencies().size(); } } }); String methods = null; for (Iterator i = lActions.iterator(); i.hasNext();) { ValidatorAction va = (ValidatorAction) i.next(); if (methods == null) { methods = va.getMethod() + "(form)"; } else { methods += " && " + va.getMethod() + "(form)"; } } results.append(getJavascriptBegin(methods)); for (Iterator i = lActions.iterator(); i.hasNext();) { ValidatorAction va = (ValidatorAction) i.next(); String jscriptVar = null; String functionName = null; if (va.getJsFunctionName() != null && va.getJsFunctionName().length() > 0) { functionName = va.getJsFunctionName(); } else { functionName = va.getName(); } if (isStruts11()) { results.append(" function " + functionName + " () { \n"); } else { results.append(" function " + formName + "_" + functionName + " () { \n"); } for (Iterator x = form.getFields().iterator(); x.hasNext();) { Field field = (Field) x.next(); // Skip indexed fields for now until there is a good way to handle // error messages (and the length of the list (could retrieve from scope?)) if (field.isIndexed() || field.getPage() != page || !field.isDependency(va.getName())) { continue; } String message = Resources.getMessage(messages, locale, va, field); message = (message != null) ? message : ""; jscriptVar = this.getNextVar(jscriptVar); results.append(" this." + jscriptVar + " = new Array(\"" + getFormClientId() + ":" + field.getKey() + "\", \"" + message + "\", "); results.append("new Function (\"varName\", \""); Map vars = field.getVars(); // Loop through the field's variables. Iterator varsIterator = vars.keySet().iterator(); while (varsIterator.hasNext()) { String varName = (String) varsIterator.next(); Var var = (Var) vars.get(varName); String varValue = var.getValue(); String jsType = var.getJsType(); // skip requiredif variables field, fieldIndexed, fieldTest, fieldValue if (varName.startsWith("field")) { continue; } if (Var.JSTYPE_INT.equalsIgnoreCase(jsType)) { results.append("this." + varName + "=" + ValidatorUtil.replace(varValue, "\\", "\\\\") + "; "); } else if (Var.JSTYPE_REGEXP.equalsIgnoreCase(jsType)) { results.append("this." + varName + "=/" + ValidatorUtil.replace(varValue, "\\", "\\\\") + "/; "); } else if (Var.JSTYPE_STRING.equalsIgnoreCase(jsType)) { results.append("this." + varName + "='" + ValidatorUtil.replace(varValue, "\\", "\\\\") + "'; "); // So everyone using the latest format doesn't need to change their xml files immediately. } else if ("mask".equalsIgnoreCase(varName)) { results.append("this." + varName + "=/" + ValidatorUtil.replace(varValue, "\\", "\\\\") + "/; "); } else { results.append("this." + varName + "='" + ValidatorUtil.replace(varValue, "\\", "\\\\") + "'; "); } } results.append(" return this[varName];\"));\n"); } results.append(" } \n\n"); } } else if ("true".equalsIgnoreCase(staticJavascript)) { results.append(this.getStartElement()); if ("true".equalsIgnoreCase(htmlComment)) { results.append(htmlBeginComment); } } } if ("true".equalsIgnoreCase(staticJavascript)) { results.append(getJavascriptStaticMethods(resources)); } if (form != null && ("true".equalsIgnoreCase(dynamicJavascript) || "true".equalsIgnoreCase(staticJavascript))) { results.append(getJavascriptEnd()); } JspWriter writer = pageContext.getOut(); try { writer.print(results.toString()); } catch (IOException e) { throw new JspException(e.getMessage()); } return (EVAL_BODY_TAG); }
From source file:org.apache.struts.taglib.html.JavascriptValidatorTag.java
/** * Generates the dynamic JavaScript for the form. * * @param config/*w w w . j av a2s .com*/ * @param resources * @param locale * @param form */ private String createDynamicJavascript(ModuleConfig config, ValidatorResources resources, Locale locale, Form form) throws JspException { StringBuffer results = new StringBuffer(); MessageResources messages = TagUtils.getInstance().retrieveMessageResources(pageContext, bundle, true); HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); ServletContext application = pageContext.getServletContext(); List actions = this.createActionList(resources, form); final String methods = this.createMethods(actions, this.stopOnError(config)); String formName = form.getName(); jsFormName = formName; if (jsFormName.charAt(0) == '/') { String mappingName = TagUtils.getInstance().getActionMappingName(jsFormName); ActionMapping mapping = (ActionMapping) config.findActionConfig(mappingName); if (mapping == null) { JspException e = new JspException(messages.getMessage("formTag.mapping", mappingName)); pageContext.setAttribute(Globals.EXCEPTION_KEY, e, PageContext.REQUEST_SCOPE); throw e; } jsFormName = mapping.getAttribute(); } results.append(this.getJavascriptBegin(methods)); for (Iterator i = actions.iterator(); i.hasNext();) { ValidatorAction va = (ValidatorAction) i.next(); int jscriptVar = 0; String functionName = null; if ((va.getJsFunctionName() != null) && (va.getJsFunctionName().length() > 0)) { functionName = va.getJsFunctionName(); } else { functionName = va.getName(); } results.append(" function " + jsFormName + "_" + functionName + " () { \n"); for (Iterator x = form.getFields().iterator(); x.hasNext();) { Field field = (Field) x.next(); // Skip indexed fields for now until there is a good way to // handle error messages (and the length of the list (could // retrieve from scope?)) if (field.isIndexed() || (field.getPage() != page) || !field.isDependency(va.getName())) { continue; } String message = Resources.getMessage(application, request, messages, locale, va, field); message = (message != null) ? message : ""; // prefix variable with 'a' to make it a legal identifier results.append(" this.a" + jscriptVar++ + " = new Array(\"" + field.getKey() + "\", \"" + escapeQuotes(message) + "\", "); results.append("new Function (\"varName\", \""); Map vars = field.getVars(); // Loop through the field's variables. Iterator varsIterator = vars.keySet().iterator(); while (varsIterator.hasNext()) { String varName = (String) varsIterator.next(); Var var = (Var) vars.get(varName); String varValue = Resources.getVarValue(var, application, request, false); String jsType = var.getJsType(); // skip requiredif variables field, fieldIndexed, fieldTest, // fieldValue if (varName.startsWith("field")) { continue; } String varValueEscaped = escapeJavascript(varValue); if (Var.JSTYPE_INT.equalsIgnoreCase(jsType)) { results.append("this." + varName + "=" + varValueEscaped + "; "); } else if (Var.JSTYPE_REGEXP.equalsIgnoreCase(jsType)) { results.append("this." + varName + "=/" + varValueEscaped + "/; "); } else if (Var.JSTYPE_STRING.equalsIgnoreCase(jsType)) { results.append("this." + varName + "='" + varValueEscaped + "'; "); // So everyone using the latest format doesn't need to // change their xml files immediately. } else if ("mask".equalsIgnoreCase(varName)) { results.append("this." + varName + "=/" + varValueEscaped + "/; "); } else { results.append("this." + varName + "='" + varValueEscaped + "'; "); } } results.append(" return this[varName];\"));\n"); } results.append(" } \n\n"); } return results.toString(); }
From source file:org.apache.struts.validator.FieldChecks.java
/** * Checks if the field isn't null and length of the field is greater than * zero not including whitespace.//from w ww. j av a2s .co m * * @param bean The bean validation is being performed on. * @param va The <code>ValidatorAction</code> that is currently * being performed. * @param field The <code>Field</code> object associated with the * current field being validated. * @param errors The <code>ActionMessages</code> object to add errors * to if any validation errors occur. * @param validator The <code>Validator</code> instance, used to access * other field values. * @param request Current request object. * @return true if meets stated requirements, false otherwise. */ public static boolean validateRequired(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request) { String value = null; value = evaluateBean(bean, field); if (GenericValidator.isBlankOrNull(value)) { errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field)); return false; } else { return true; } }
From source file:org.apache.struts.validator.FieldChecks.java
/** * Checks if the field isn't null based on the values of other fields. * * @param bean The bean validation is being performed on. * @param va The <code>ValidatorAction</code> that is currently * being performed./*w w w. j a v a 2 s . c o m*/ * @param field The <code>Field</code> object associated with the * current field being validated. * @param errors The <code>ActionMessages</code> object to add errors * to if any validation errors occur. * @param validator The <code>Validator</code> instance, used to access * other field values. * @param request Current request object. * @return true if meets stated requirements, false otherwise. */ public static boolean validateRequiredIf(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request) { Object form = validator.getParameterValue(org.apache.commons.validator.Validator.BEAN_PARAM); String value = null; boolean required = false; value = evaluateBean(bean, field); int i = 0; String fieldJoin = "AND"; if (!GenericValidator.isBlankOrNull(field.getVarValue("fieldJoin"))) { fieldJoin = field.getVarValue("fieldJoin"); } if (fieldJoin.equalsIgnoreCase("AND")) { required = true; } while (!GenericValidator.isBlankOrNull(field.getVarValue("field[" + i + "]"))) { String dependProp = field.getVarValue("field[" + i + "]"); String dependTest = field.getVarValue("fieldTest[" + i + "]"); String dependTestValue = field.getVarValue("fieldValue[" + i + "]"); String dependIndexed = field.getVarValue("fieldIndexed[" + i + "]"); if (dependIndexed == null) { dependIndexed = "false"; } String dependVal = null; boolean thisRequired = false; if (field.isIndexed() && dependIndexed.equalsIgnoreCase("true")) { String key = field.getKey(); if ((key.indexOf("[") > -1) && (key.indexOf("]") > -1)) { String ind = key.substring(0, key.indexOf(".") + 1); dependProp = ind + dependProp; } } dependVal = ValidatorUtils.getValueAsString(form, dependProp); if (dependTest.equals(FIELD_TEST_NULL)) { if ((dependVal != null) && (dependVal.length() > 0)) { thisRequired = false; } else { thisRequired = true; } } if (dependTest.equals(FIELD_TEST_NOTNULL)) { if ((dependVal != null) && (dependVal.length() > 0)) { thisRequired = true; } else { thisRequired = false; } } if (dependTest.equals(FIELD_TEST_EQUAL)) { thisRequired = dependTestValue.equalsIgnoreCase(dependVal); } if (fieldJoin.equalsIgnoreCase("AND")) { required = required && thisRequired; } else { required = required || thisRequired; } i++; } if (required) { if (GenericValidator.isBlankOrNull(value)) { errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field)); return false; } else { return true; } } return true; }
From source file:org.apache.struts.validator.FieldChecks.java
/** * Checks if the field matches the regular expression in the field's mask * attribute./*from w w w . ja v a 2 s . com*/ * * @param bean The bean validation is being performed on. * @param va The <code>ValidatorAction</code> that is currently * being performed. * @param field The <code>Field</code> object associated with the * current field being validated. * @param errors The <code>ActionMessages</code> object to add errors * to if any validation errors occur. * @param validator The <code>Validator</code> instance, used to access * other field values. * @param request Current request object. * @return true if field matches mask, false otherwise. */ public static boolean validateMask(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request) { String value = null; value = evaluateBean(bean, field); try { String mask = Resources.getVarValue("mask", field, validator, request, true); if (value != null && value.length() > 0 && !GenericValidator.matchRegexp(value, mask)) { errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field)); return false; } else { return true; } } catch (Exception e) { processFailure(errors, field, "mask", e); return false; } }