当前位置: 首页>>代码示例>>Java>>正文


Java GenericValidator.maxLength方法代码示例

本文整理汇总了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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:46,代码来源:FieldChecks.java

示例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;
    }
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:12,代码来源:EctValidation.java

示例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;
}
 
开发者ID:SonarSource,项目名称:sonar-scanner-maven,代码行数:56,代码来源:FieldChecks.java

示例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;
    }
 
开发者ID:oscarservice,项目名称:oscar-old,代码行数:13,代码来源:EctValidation.java

示例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);
        }
    }
}
 
开发者ID:primecloud-controller-org,项目名称:primecloud-controller,代码行数:18,代码来源:ValidateUtil.java

示例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);
}
 
开发者ID:ctc-g,项目名称:sinavi-jfw,代码行数:11,代码来源:Validators.java


注:本文中的org.apache.commons.validator.GenericValidator.maxLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。