Example usage for org.springframework.validation BindingResult getGlobalErrors

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

Introduction

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

Prototype

List<ObjectError> getGlobalErrors();

Source Link

Document

Get all global errors.

Usage

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

/**
 * {@inheritDoc}/*from   w w w  . jav  a 2 s  . co m*/
 */
@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:org.broadleafcommerce.openadmin.web.controller.entity.AdminBasicEntityController.java

/**
 * Populates the given <b>json</b> response object based on the given <b>form</b> and <b>result</b>
 * @return the same <b>result</b> that was passed in
 *///w  w w .  ja v  a2s.  co m
protected JsonResponse populateJsonValidationErrors(EntityForm form, BindingResult result, JsonResponse json) {
    List<Map<String, Object>> errors = new ArrayList<Map<String, Object>>();
    for (FieldError e : result.getFieldErrors()) {
        Map<String, Object> errorMap = new HashMap<String, Object>();
        errorMap.put("errorType", "field");
        String fieldName = e.getField().substring(e.getField().indexOf("[") + 1, e.getField().indexOf("]"))
                .replace("_", "-");
        errorMap.put("field", fieldName);

        errorMap.put("message", translateErrorMessage(e));
        errorMap.put("code", e.getCode());
        String tabFieldName = fieldName.replaceAll("-+", ".");
        Tab errorTab = form.findTabForField(tabFieldName);
        if (errorTab != null) {
            errorMap.put("tab", errorTab.getTitle());
        }
        errors.add(errorMap);
    }
    for (ObjectError e : result.getGlobalErrors()) {
        Map<String, Object> errorMap = new HashMap<String, Object>();
        errorMap.put("errorType", "global");
        errorMap.put("code", e.getCode());
        errorMap.put("message", translateErrorMessage(e));
        errors.add(errorMap);
    }
    json.with("errors", errors);

    return json;
}