本文整理汇总了Java中org.apache.commons.validator.GenericValidator.maxLength方法的典型用法代码示例。如果您正苦于以下问题:Java GenericValidator.maxLength方法的具体用法?Java GenericValidator.maxLength怎么用?Java GenericValidator.maxLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.validator.GenericValidator
的用法示例。
在下文中一共展示了GenericValidator.maxLength方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateMaxLength
import org.apache.commons.validator.GenericValidator; //导入方法依赖的package包/类
/**
* Checks if the field's length is less than or equal to the maximum value.
* A <code>Null</code> will be considered an error.
*
* @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 stated conditions met.
*/
public static boolean validateMaxLength(Object bean,
ValidatorAction va, Field field,
ActionMessages errors,
Validator validator,
HttpServletRequest request) {
String value = null;
if (isString(bean)) {
value = (String) bean;
} else {
value = ValidatorUtils.getValueAsString(bean, field.getProperty());
}
if (value != null) {
try {
int max = Integer.parseInt(field.getVarValue("maxlength"));
if (!GenericValidator.maxLength(value, max)) {
errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
return false;
}
} catch (Exception e) {
errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
return false;
}
}
return true;
}
示例2: maxLength
import org.apache.commons.validator.GenericValidator; //导入方法依赖的package包/类
public boolean maxLength(Integer iMax, String inputValue){
boolean validation = true;
if (iMax != null && iMax!=0){
if(!GenericValidator.maxLength(inputValue, iMax)){
validation=false;
}
}
return validation;
}
示例3: validateMaxLength
import org.apache.commons.validator.GenericValidator; //导入方法依赖的package包/类
/**
* Checks if the field's length is less than or equal to the maximum
* value. A <code>Null</code> will be considered an error.
*
* @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 stated conditions met.
*/
public static boolean validateMaxLength(Object bean, ValidatorAction va,
Field field, ActionMessages errors, Validator validator,
HttpServletRequest request) {
String value = null;
value = evaluateBean(bean, field);
if (value != null) {
try {
String maxVar =
Resources.getVarValue("maxlength", field, validator,
request, true);
int max = Integer.parseInt(maxVar);
boolean isValid = false;
String endLth = Resources.getVarValue("lineEndLength", field,
validator, request, false);
if (GenericValidator.isBlankOrNull(endLth)) {
isValid = GenericValidator.maxLength(value, max);
} else {
isValid = GenericValidator.maxLength(value, max,
Integer.parseInt(endLth));
}
if (!isValid) {
errors.add(field.getKey(),
Resources.getActionMessage(validator, request, va, field));
return false;
}
} catch (Exception e) {
processFailure(errors, field, "maxlength", e);
return false;
}
}
return true;
}
示例4: maxLength
import org.apache.commons.validator.GenericValidator; //导入方法依赖的package包/类
public boolean maxLength(int iMax, String inputValue){
boolean validation = true;
org.apache.commons.validator.GenericValidator gValidator = new org.apache.commons.validator.GenericValidator();
if (iMax!=0){
if(!GenericValidator.maxLength(inputValue, iMax)){
validation=false;
}
}
return validation;
}
示例5: lengthInRange
import org.apache.commons.validator.GenericValidator; //导入方法依赖的package包/类
/**
* 桁数チェック
*
* @param value 入力チェック対象の値
* @param minLength 最小桁数
* @param maxLength 最大桁数
* @param code 入力チェックエラー時のメッセージコード
* @param params 入力チェックエラー時のメッセージパラメータ
*/
public static void lengthInRange(String value, int minLength, int maxLength, String code, Object[] params) {
if (value != null) {
if (GenericValidator.minLength(value, minLength) == false
|| GenericValidator.maxLength(value, maxLength) == false) {
throw new AutoApplicationException(code, params);
}
}
}
示例6: maxLength
import org.apache.commons.validator.GenericValidator; //导入方法依赖的package包/类
/**
* 指定された文字列の長さが指定したサイズと等しいか、それよりも小さいかを検査します。
* アルゴリズムは、{@link GenericValidator#maxLength(String, int)}を利用しています。
* @param suspect 検査対象
* @param size サイズ
* @return GenericValidator#maxLength(String, int)の結果
*/
public static boolean maxLength(CharSequence suspect, int size) {
return GenericValidator.maxLength(suspect.toString(), size);
}