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


Java ValidationErrors.get方法代码示例

本文整理汇总了Java中net.sourceforge.stripes.validation.ValidationErrors.get方法的典型用法代码示例。如果您正苦于以下问题:Java ValidationErrors.get方法的具体用法?Java ValidationErrors.get怎么用?Java ValidationErrors.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.sourceforge.stripes.validation.ValidationErrors的用法示例。


在下文中一共展示了ValidationErrors.get方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: hasErrors

import net.sourceforge.stripes.validation.ValidationErrors; //导入方法依赖的package包/类
/** Indicates if validation errors exist for the given field of the given {@link ActionBean}. */
public static boolean hasErrors(ActionBean actionBean, String field) {
    if (actionBean == null || field == null)
        return false;

    ActionBeanContext context = actionBean.getContext();
    if (context == null)
        return false;

    ValidationErrors errors = context.getValidationErrors();
    if (errors == null || errors.isEmpty())
        return false;

    List<ValidationError> fieldErrors = errors.get(field);
    return fieldErrors != null && fieldErrors.size() > 0;
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:17,代码来源:ElFunctions.java

示例2: loadErrors

import net.sourceforge.stripes.validation.ValidationErrors; //导入方法依赖的package包/类
/**
 * Find errors that are related to the form field this input tag represents and place
 * them in an instance variable to use during error rendering.
 */
protected void loadErrors() throws StripesJspException {
    ActionBean actionBean = getActionBean();
    if (actionBean != null) {
        ValidationErrors validationErrors = actionBean.getContext().getValidationErrors();

        if (validationErrors != null) {
            this.fieldErrors = validationErrors.get(getName());
        }
    }
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:15,代码来源:InputTagSupport.java

示例3: setFocusOnFieldIfRequired

import net.sourceforge.stripes.validation.ValidationErrors; //导入方法依赖的package包/类
/**
 * Checks to see if the field should receive focus either because it is the named
 * field for receiving focus, because it is the first field in the form (and first
 * field focus was specified), or because it is the first field in error.
 *
 * @param tag the input tag being registered with the form
 */
protected void setFocusOnFieldIfRequired(InputTagSupport tag) {
    // Decide whether or not this field should be focused
    if (this.focus != null && !this.focusSet) {
        ActionBean bean = getActionBean();
        ValidationErrors errors = bean == null ? null : bean.getContext().getValidationErrors();

        // If there are validation errors, select the first field in error
        if (errors != null && errors.hasFieldErrors()) {
            List<ValidationError> fieldErrors = errors.get(tag.getName());
            if (fieldErrors != null && fieldErrors.size() > 0) {
                tag.setFocus(true);
                this.focusSet = true;
            }
        }
        // Else set the named field, or the first field if that's desired
        else if (this.focus.equals(tag.getName())) {
                tag.setFocus(true);
                this.focusSet = true;
        }
        else if ("".equals(this.focus) || "first".equalsIgnoreCase(this.focus)) {
            if ( !(tag instanceof InputHiddenTag) ) {
                tag.setFocus(true);
                this.focusSet = true;
            }
        }
    }
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:35,代码来源:FormTag.java

示例4: removeDuplicates

import net.sourceforge.stripes.validation.ValidationErrors; //导入方法依赖的package包/类
/**
 * Sometimes error messages can be the same even although different fields
 * are involved. Also, if 2 different types of validations occur on one
 * field, then stripes will display them both. We want neither, so here we
 * attempts to remove any duplicates.
 * 
 * @param validationErrors
 */
protected void removeDuplicates(ValidationErrors validationErrors) {
    List<String> allErrorMessages = new ArrayList<String>();

    if (validationErrors.size() > 0) {
        Set<String> keys = validationErrors.keySet();

        for (String field : keys) {
            List<ValidationError> errors = validationErrors.get(field);
            // Remember errors we want to remove.
            List<ValidationError> errorsToRemove = new ArrayList<>();
            // Remember errors that we want to add in place of the removed
            // ones.
            Set<ValidationError> errorsToAdd = new HashSet<>();

            int count = 0;
            for (ValidationError error : errors) {
                // If a field has more than one error, we remove all of the
                // rest. We only want to show one error at
                // a time per field.
                if (errors.size() > 0 && count > 0) {
                    errorsToRemove.add(error);
                    continue;
                }

                // Set the bean class or strips end up with a NullPointer.
                // error.setBeanclass(app.getActionBean().getClass()); //
                // Not needed in Geemvc.

                String message = error.getMessage(app.getCurrentLocale());

                // If this message already exists, we remove it from the
                // list of errors.
                if (allErrorMessages.contains(message)) {
                    errorsToRemove.add(error);
                    // Errors that we remove need to be replaced with some
                    // empty error or stripes will not
                    // re-populate the input-field.
                    errorsToAdd.add(new SimpleError("", null, error.getFieldValue()));
                } else {
                    // Remember the error message in the global list so that
                    // we can check for duplicates in other
                    // fields.
                    allErrorMessages.add(message);
                }

                count++;
            }

            if (errorsToRemove.size() > 0) {
                errors.removeAll(errorsToRemove);
                errors.addAll(errorsToAdd);
            }
        }
    }
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:64,代码来源:ActionBeanPropertyBinder.java


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