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;
}
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;
}
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();
}
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;
}
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();
}
Aggregations