Search in sources :

Example 96 with ObjectError

use of org.springframework.validation.ObjectError in project collect by openforis.

the class AbstractPersistedObjectEditFormController method save.

protected Response save(@Validated F form, BindingResult result) {
    List<ObjectError> errors = result.getAllErrors();
    SimpleFormUpdateResponse response;
    if (errors.isEmpty()) {
        T item = loadOrCreateItem(form);
        copyFormIntoItem(form, item);
        itemManager.save(item, getLoggedUser());
        F responseForm = createFormInstance(item);
        response = new SimpleFormUpdateResponse(responseForm);
    } else {
        response = new SimpleFormUpdateResponse(errors);
    }
    return response;
}
Also used : ObjectError(org.springframework.validation.ObjectError) GET(org.springframework.web.bind.annotation.RequestMethod.GET) POST(org.springframework.web.bind.annotation.RequestMethod.POST)

Example 97 with ObjectError

use of org.springframework.validation.ObjectError in project collect by openforis.

the class BasicController method generateFormValidationResponse.

protected Response generateFormValidationResponse(BindingResult result) {
    List<ObjectError> errors = result.getAllErrors();
    Response response = new Response();
    if (!errors.isEmpty()) {
        response.setErrorStatus();
        response.addObject("errors", errors);
    }
    return response;
}
Also used : Response(org.openforis.commons.web.Response) ObjectError(org.springframework.validation.ObjectError)

Example 98 with ObjectError

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

the class WebExchangeBindException method getMessage.

/**
 * Returns diagnostic information about the errors held in this object.
 */
@Override
public String getMessage() {
    MethodParameter parameter = getMethodParameter();
    Assert.state(parameter != null, "No MethodParameter");
    StringBuilder sb = new StringBuilder("Validation failed for argument at index ").append(parameter.getParameterIndex()).append(" in method: ").append(parameter.getExecutable().toGenericString()).append(", with ").append(this.bindingResult.getErrorCount()).append(" error(s): ");
    for (ObjectError error : this.bindingResult.getAllErrors()) {
        sb.append('[').append(error).append("] ");
    }
    return sb.toString();
}
Also used : ObjectError(org.springframework.validation.ObjectError) MethodParameter(org.springframework.core.MethodParameter)

Example 99 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 100 with ObjectError

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

the class ValidatorFactoryTests method testSpringValidationWithAutowiredValidator.

@Test
public void testSpringValidationWithAutowiredValidator() {
    ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(LocalValidatorFactoryBean.class);
    LocalValidatorFactoryBean validator = ctx.getBean(LocalValidatorFactoryBean.class);
    ValidPerson person = new ValidPerson();
    person.expectsAutowiredValidator = true;
    person.setName("Juergen");
    person.getAddress().setStreet("Juergen's Street");
    BeanPropertyBindingResult result = new BeanPropertyBindingResult(person, "person");
    validator.validate(person, result);
    assertThat(result.getErrorCount()).isEqualTo(1);
    ObjectError globalError = result.getGlobalError();
    List<String> errorCodes = Arrays.asList(globalError.getCodes());
    assertThat(errorCodes.size()).isEqualTo(2);
    assertThat(errorCodes.contains("NameAddressValid.person")).isTrue();
    assertThat(errorCodes.contains("NameAddressValid")).isTrue();
    ctx.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) ObjectError(org.springframework.validation.ObjectError) Test(org.junit.jupiter.api.Test)

Aggregations

ObjectError (org.springframework.validation.ObjectError)106 FieldError (org.springframework.validation.FieldError)19 BindingResult (org.springframework.validation.BindingResult)17 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)17 BindException (org.springframework.validation.BindException)14 ArrayList (java.util.ArrayList)13 MapBindingResult (org.springframework.validation.MapBindingResult)13 Test (org.junit.jupiter.api.Test)12 ModelAndView (org.springframework.web.servlet.ModelAndView)10 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)7 Test (org.junit.Test)6 BusinessRuleException (org.mifos.service.BusinessRuleException)6 Errors (org.springframework.validation.Errors)6 MethodArgumentNotValidException (org.springframework.web.bind.MethodArgumentNotValidException)6 DocumentBuilder (javax.xml.parsers.DocumentBuilder)5 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)5 OnmsLocationMonitor (org.opennms.netmgt.model.OnmsLocationMonitor)5 LocationMonitorIdCommand (org.opennms.web.svclayer.model.LocationMonitorIdCommand)5 Document (org.w3c.dom.Document)5 Element (org.w3c.dom.Element)5