?? customvalidator.java
字號:
package org.ithinking.utils;
import java.io.Serializable;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.validator.Field;
import org.apache.commons.validator.GenericValidator;
import org.apache.commons.validator.ValidatorAction;
import org.apache.commons.validator.util.ValidatorUtils;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.validator.Resources;
//自定義校驗規則工具類
public class CustomValidator implements Serializable {
//比較兩個字段是否相等
public static boolean validateTwoFields(Object bean, ValidatorAction va,
Field field, ActionErrors errors, HttpServletRequest request
) {
String value = ValidatorUtils.getValueAsString(bean, field
.getProperty());
String sProperty2 = field.getVarValue("secondProperty");
String value2 = ValidatorUtils.getValueAsString(bean, sProperty2);
if (!GenericValidator.isBlankOrNull(value)) {
try {
if (!value.equals(value2)) {
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;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -