Search in sources :

Example 46 with ObjectError

use of org.springframework.validation.ObjectError in project spring-boot by spring-projects.

the class BindFailureAnalyzer method analyze.

@Override
protected FailureAnalysis analyze(Throwable rootFailure, BindException cause) {
    if (CollectionUtils.isEmpty(cause.getAllErrors())) {
        return null;
    }
    StringBuilder description = new StringBuilder(String.format("Binding to target %s failed:%n", cause.getTarget()));
    for (ObjectError error : cause.getAllErrors()) {
        if (error instanceof FieldError) {
            FieldError fieldError = (FieldError) error;
            description.append(String.format("%n    Property: %s", cause.getObjectName() + "." + fieldError.getField()));
            description.append(String.format("%n    Value: %s", fieldError.getRejectedValue()));
        }
        description.append(String.format("%n    Reason: %s%n", error.getDefaultMessage()));
    }
    return new FailureAnalysis(description.toString(), "Update your application's configuration", cause);
}
Also used : ObjectError(org.springframework.validation.ObjectError) FieldError(org.springframework.validation.FieldError) FailureAnalysis(org.springframework.boot.diagnostics.FailureAnalysis)

Example 47 with ObjectError

use of org.springframework.validation.ObjectError in project spring-framework by spring-projects.

the class BindStatus method initErrorCodes.

/**
	 * Extract the error codes from the ObjectError list.
	 */
private void initErrorCodes() {
    this.errorCodes = new String[this.objectErrors.size()];
    for (int i = 0; i < this.objectErrors.size(); i++) {
        ObjectError error = this.objectErrors.get(i);
        this.errorCodes[i] = error.getCode();
    }
}
Also used : ObjectError(org.springframework.validation.ObjectError)

Example 48 with ObjectError

use of org.springframework.validation.ObjectError in project spring-framework by spring-projects.

the class BindStatus method initErrorCodes.

/**
	 * Extract the error codes from the ObjectError list.
	 */
private static String[] initErrorCodes(List<? extends ObjectError> objectErrors) {
    String[] errorCodes = new String[objectErrors.size()];
    for (int i = 0; i < objectErrors.size(); i++) {
        ObjectError error = objectErrors.get(i);
        errorCodes[i] = error.getCode();
    }
    return errorCodes;
}
Also used : ObjectError(org.springframework.validation.ObjectError)

Example 49 with ObjectError

use of org.springframework.validation.ObjectError in project spring-boot by spring-projects.

the class DefaultErrorAttributesTests method extractMethodArgumentNotValidExceptionBindingResultErrors.

@Test
public void extractMethodArgumentNotValidExceptionBindingResultErrors() throws Exception {
    BindingResult bindingResult = new MapBindingResult(Collections.singletonMap("a", "b"), "objectName");
    bindingResult.addError(new ObjectError("c", "d"));
    Exception ex = new MethodArgumentNotValidException(null, bindingResult);
    testBindingResult(bindingResult, ex);
}
Also used : BindingResult(org.springframework.validation.BindingResult) MapBindingResult(org.springframework.validation.MapBindingResult) ObjectError(org.springframework.validation.ObjectError) MapBindingResult(org.springframework.validation.MapBindingResult) MethodArgumentNotValidException(org.springframework.web.bind.MethodArgumentNotValidException) ServletException(javax.servlet.ServletException) MethodArgumentNotValidException(org.springframework.web.bind.MethodArgumentNotValidException) BindException(org.springframework.validation.BindException) Test(org.junit.Test)

Example 50 with ObjectError

use of org.springframework.validation.ObjectError in project spring-boot by spring-projects.

the class DefaultErrorAttributesTests method extractBindingResultErrors.

@Test
public void extractBindingResultErrors() throws Exception {
    BindingResult bindingResult = new MapBindingResult(Collections.singletonMap("a", "b"), "objectName");
    bindingResult.addError(new ObjectError("c", "d"));
    Exception ex = new BindException(bindingResult);
    testBindingResult(bindingResult, ex);
}
Also used : BindingResult(org.springframework.validation.BindingResult) MapBindingResult(org.springframework.validation.MapBindingResult) ObjectError(org.springframework.validation.ObjectError) BindException(org.springframework.validation.BindException) MapBindingResult(org.springframework.validation.MapBindingResult) ServletException(javax.servlet.ServletException) MethodArgumentNotValidException(org.springframework.web.bind.MethodArgumentNotValidException) BindException(org.springframework.validation.BindException) Test(org.junit.Test)

Aggregations

ObjectError (org.springframework.validation.ObjectError)57 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 BindException (org.springframework.validation.BindException)10 FieldError (org.springframework.validation.FieldError)8 BusinessRuleException (org.mifos.service.BusinessRuleException)7 ModelAndView (org.springframework.web.servlet.ModelAndView)7 BindingResult (org.springframework.validation.BindingResult)6 DocumentBuilder (javax.xml.parsers.DocumentBuilder)5 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)5 Test (org.junit.Test)5 OnmsLocationMonitor (org.opennms.netmgt.model.OnmsLocationMonitor)5 LocationMonitorIdCommand (org.opennms.web.svclayer.model.LocationMonitorIdCommand)5 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)5 MapBindingResult (org.springframework.validation.MapBindingResult)5 Document (org.w3c.dom.Document)5 Element (org.w3c.dom.Element)5 ArrayList (java.util.ArrayList)3 Errors (org.springframework.validation.Errors)3 MethodArgumentNotValidException (org.springframework.web.bind.MethodArgumentNotValidException)3 ServletException (javax.servlet.ServletException)2