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


Java ValidationErrors.size方法代码示例

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


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

示例1: isFormInError

import net.sourceforge.stripes.validation.ValidationErrors; //导入方法依赖的package包/类
/**
 * Helper method that will check to see if the form containing this tag is being rendered
 * as a result of validation errors.  This is not actually used by the default strategy,
 * but is here to help subclasses provide different behaviour for when the form is rendering
 * normally vs. in error.
 *
 * @param tag the tag that is being repopulated
 * @return boolean true if the form is in error, false otherwise
 */
protected boolean isFormInError(InputTagSupport tag) throws StripesJspException {
    boolean inError = false;

    ActionBean actionBean = tag.getParentFormTag().getActionBean();
    if (actionBean != null) {
        ValidationErrors errors = actionBean.getContext().getValidationErrors(); 
        inError = (errors != null && errors.size() > 0);
    }

    return inError;
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:21,代码来源:DefaultPopulationStrategy.java

示例2: handleValidationErrors

import net.sourceforge.stripes.validation.ValidationErrors; //导入方法依赖的package包/类
/**
 * Responsible for checking to see if validation errors exist and if so for handling
 * them appropriately.  This includes ensuring that the error objects have all information
 * necessary to render themselves appropriately and invoking any error handling code.
 *
 * @param ctx the ExecutionContext being used to process the current request
 * @return a Resolution if the error handling code determines that some kind of resolution
 *         should be processed in favor of continuing on to handler invocation
 */
public static Resolution handleValidationErrors(ExecutionContext ctx) throws Exception {
    DontValidate annotation = ctx.getHandler().getAnnotation(DontValidate.class);
    boolean doValidate = annotation == null || !annotation.ignoreBindingErrors();

    // If we have errors, add the action path to them
    fillInValidationErrors(ctx);

    Resolution resolution = null;
    if (doValidate) {
        ActionBean bean = ctx.getActionBean();
        ActionBeanContext context = ctx.getActionBeanContext();
        ValidationErrors errors = context.getValidationErrors();

        // Now if we have errors and the bean wants to handle them...
        if (errors.size() > 0 && bean instanceof ValidationErrorHandler) {
            resolution = ((ValidationErrorHandler) bean).handleValidationErrors(errors);
            fillInValidationErrors(ctx);
        }

        // If there are still errors see if we need to lookup the resolution
        if (errors.size() > 0 && resolution == null) {
            logValidationErrors(context);
            resolution = context.getSourcePageResolution();
        }
    }

    return resolution;
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:38,代码来源:DispatcherHelper.java

示例3: fillInValidationErrors

import net.sourceforge.stripes.validation.ValidationErrors; //导入方法依赖的package包/类
/**
 * Makes sure that validation errors have all the necessary information to render
 * themselves properly, including the UrlBinding of the action bean and the field
 * value if it hasn't already been set.
 *
 * @param ctx the ExecutionContext being used to process the current request
 */
public static void fillInValidationErrors(ExecutionContext ctx) {
    ActionBeanContext context = ctx.getActionBeanContext();
    ValidationErrors errors = context.getValidationErrors();

    if (errors.size() > 0) {
        String formAction = StripesFilter.getConfiguration().getActionResolver()
                .getUrlBinding(ctx.getActionBean().getClass());
        HttpServletRequest request = ctx.getActionBeanContext().getRequest();

        /** Since we don't pass form action down the stack, we add it to the errors here. */
        for (Map.Entry<String, List<ValidationError>> entry : errors.entrySet()) {
            String parameterName = entry.getKey();
            List<ValidationError> listOfErrors = entry.getValue();

            for (ValidationError error : listOfErrors) {
                // Make sure we process each error only once, no matter how often we're called
                if (error.getActionPath() == null) {
                    error.setActionPath(formAction);
                    error.setBeanclass(ctx.getActionBean().getClass());

                    // If the value isn't set, set it, otherwise encode the one that's there
                    if (error.getFieldValue() == null) {
                        error.setFieldValue(HtmlUtil.encode(request.getParameter(parameterName)));
                    }
                    else {
                        error.setFieldValue(HtmlUtil.encode(error.getFieldValue()));
                    }
                }
            }
        }
    }
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:40,代码来源:DispatcherHelper.java

示例4: handleValidationErrors

import net.sourceforge.stripes.validation.ValidationErrors; //导入方法依赖的package包/类
public Resolution handleValidationErrors(ValidationErrors errors)
        throws Exception {
    if (errors.size() > 0) {
        getLogger().debug("" + getNormalizedRequestParameters());
        getLogger().error("\n\nPlease override handleValidationErrors() in your current action bean");
        getLogger().error("To see the on the current page, please override getErrorPage() with the name of the current page and remember to call this tag <stripes:errors/>");
        Set<String> keys = errors.keySet();
        for (String key : keys) {
            getLogger().error("Validation Error Key : "
                    + errors.get(key).get(0).getFieldName());
            getLogger().error("Params are : " + getNormalizedRequestParameters());
        }
    }
    return new ForwardResolution(getErrorPage());
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:16,代码来源:BaseActionBean.java

示例5: doPostConversionValidations

import net.sourceforge.stripes.validation.ValidationErrors; //导入方法依赖的package包/类
protected void doPostConversionValidations(ActionBean bean, Map<ParameterName, List<Object>> convertedValues,
    ValidationErrors errors) {
    super.doPostConversionValidations(bean, convertedValues, errors);

    // Do not bother with further checks if validation errors already exist.
    if (errors.size() > 0) {
        removeDuplicates(errors);
        return;
    }

    String validInputCharset = app.cpStr_(VALID_INPUT_CHARSET_CONFIG_KEY);

    // Do not do any checking if no charset has been configured.
    if (validInputCharset != null) {
        Map<String, ValidationMetadata> validationInfos = super.getConfiguration().getValidationMetadataProvider()
            .getValidationMetadata(bean.getClass());

        for (Map.Entry<ParameterName, List<Object>> entry : convertedValues.entrySet()) {
            // Sort out what we need to validate this field
            ParameterName name = entry.getKey();
            List<Object> values = entry.getValue();
            ValidationMetadata validationInfo = validationInfos.get(name.getStrippedName());

            if (values.size() == 0 || validationInfo == null)
                continue;

            for (Object value : values) {
                // If the value is a string and a specific input-charset has
                // been configured,
                // we make sure that the value is valid for this charset.
                if (value instanceof String) {
                    String string = (String) value;

                    boolean isValidCharset = Charset.forName(validInputCharset).newEncoder().canEncode(string);

                    if (!isValidCharset) {
                        ValidationError error = new ScopedLocalizableError("converter.charset", "invalidCharset",
                            validInputCharset);
                        error.setFieldValue(String.valueOf(value));
                        errors.add(name.getName(), error);
                    }
                }
            }
        }
    }

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

示例6: 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.size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。