use of org.springframework.web.bind.EscapedErrors in project spring-framework by spring-projects.
the class RequestContext method getErrors.
/**
* Retrieve the Errors instance for the given bind object.
* @param name name of the bind object
* @param htmlEscape create an Errors instance with automatic HTML escaping?
* @return the Errors instance, or {@code null} if not found
*/
public Optional<Errors> getErrors(String name, boolean htmlEscape) {
if (this.errorsMap == null) {
this.errorsMap = new HashMap<>();
}
// Since there is no Optional orElse + flatMap...
Optional<Errors> optional = Optional.ofNullable(this.errorsMap.get(name));
optional = optional.isPresent() ? optional : getModelObject(BindingResult.MODEL_KEY_PREFIX + name);
return optional.map(errors -> {
if (errors instanceof BindException) {
return ((BindException) errors).getBindingResult();
} else {
return errors;
}
}).map(errors -> {
if (htmlEscape && !(errors instanceof EscapedErrors)) {
errors = new EscapedErrors(errors);
} else if (!htmlEscape && errors instanceof EscapedErrors) {
errors = ((EscapedErrors) errors).getSource();
}
this.errorsMap.put(name, errors);
return errors;
});
}
use of org.springframework.web.bind.EscapedErrors in project spring-framework by spring-projects.
the class RequestContext method getErrors.
/**
* Retrieve the Errors instance for the given bind object.
* @param name name of the bind object
* @param htmlEscape create an Errors instance with automatic HTML escaping?
* @return the Errors instance, or {@code null} if not found
*/
public Errors getErrors(String name, boolean htmlEscape) {
if (this.errorsMap == null) {
this.errorsMap = new HashMap<>();
}
Errors errors = this.errorsMap.get(name);
boolean put = false;
if (errors == null) {
errors = (Errors) getModelObject(BindingResult.MODEL_KEY_PREFIX + name);
// Check old BindException prefix for backwards compatibility.
if (errors instanceof BindException) {
errors = ((BindException) errors).getBindingResult();
}
if (errors == null) {
return null;
}
put = true;
}
if (htmlEscape && !(errors instanceof EscapedErrors)) {
errors = new EscapedErrors(errors);
put = true;
} else if (!htmlEscape && errors instanceof EscapedErrors) {
errors = ((EscapedErrors) errors).getSource();
put = true;
}
if (put) {
this.errorsMap.put(name, errors);
}
return errors;
}
Aggregations