Example usage for org.springframework.validation BindingResult hasGlobalErrors

List of usage examples for org.springframework.validation BindingResult hasGlobalErrors

Introduction

In this page you can find the example usage for org.springframework.validation BindingResult hasGlobalErrors.

Prototype

boolean hasGlobalErrors();

Source Link

Document

Are there any global errors?

Usage

From source file:com.yqboots.web.thymeleaf.processor.element.AlertElementProcessor.java

/**
 * {@inheritDoc}/*from   w  w w . j a v a  2  s .  c om*/
 */
@Override
protected List<Node> getMarkupSubstitutes(final Arguments arguments, final Element element) {
    final List<Node> nodes = new ArrayList<>();

    final String levelAttrValue = StringUtils.defaultIfBlank(element.getAttributeValue(ATTR_LEVEL),
            DEFAULT_LEVEL);

    final VariablesMap<String, Object> variables = arguments.getContext().getVariables();
    variables.values().stream().filter(new Predicate<Object>() {
        @Override
        public boolean test(final Object o) {
            return BindingResult.class.isAssignableFrom(o.getClass());
        }
    }).forEach(new Consumer<Object>() {
        @Override
        public void accept(final Object value) {
            BindingResult bindingResult = (BindingResult) value;
            if (bindingResult.hasGlobalErrors()) {
                nodes.add(build(arguments, bindingResult.getGlobalErrors(), levelAttrValue));
            }
        }
    });

    return nodes;
}

From source file:edu.zipcloud.cloudstreetmarket.core.util.ValidatorUtil.java

public static void raiseFirstError(BindingResult result) {
    if (result.hasFieldErrors()) {
        throw new IllegalArgumentException(result.getFieldError().getDefaultMessage());
    } else if (result.hasGlobalErrors()) {
        throw new IllegalArgumentException(result.getGlobalError().getDefaultMessage());
    } else if (result.hasErrors()) {
        throw new IllegalArgumentException(result.getAllErrors().get(0).getCode());
    }//from  ww w . ja va2  s.  c om
}