use of org.springframework.validation.ObjectError in project head by mifos.
the class LoanProductFormBeanValidator method convertInstallmentsByLastLoanJsr303ViolationsToSpringErrors.
private void convertInstallmentsByLastLoanJsr303ViolationsToSpringErrors(BindingResult result, int lastLoanRow, ByLastLoanAmountBean byLoanCycle, Set<ConstraintViolation<ByLastLoanAmountBean>> cycleViolations) {
for (ConstraintViolation<ByLastLoanAmountBean> constraintViolation : cycleViolations) {
ObjectError error = new ObjectError("loanProduct", new String[] { buildViolationMessage("loanProduct.installmentsByLastLoanAmount", constraintViolation) }, new Object[] { lastLoanRow + 1 }, constraintViolation.getMessage());
result.addError(error);
}
if (cycleViolations.isEmpty() && !byLoanCycle.isRangeValid()) {
ObjectError error = new ObjectError("loanProduct", new String[] { "Max.loanProduct.installmentsByLastLoanAmount.upper" }, new Object[] { lastLoanRow + 1 }, "The upper value must be greater than lower.");
result.addError(error);
}
if (cycleViolations.isEmpty() && !byLoanCycle.minIsLessThanMax()) {
ObjectError error = new ObjectError("loanProduct", new String[] { "Max.loanProduct.installmentsByLastLoanAmount.max" }, new Object[] { lastLoanRow + 1 }, "The min must be less than max.");
result.addError(error);
}
if (cycleViolations.isEmpty() && !byLoanCycle.defaultIsBetweenMinAndMax()) {
ObjectError error = new ObjectError("loanProduct", new String[] { "Max.loanProduct.installmentsByLastLoanAmount.theDefault" }, new Object[] { lastLoanRow + 1 }, "The default is not within min and max range.");
result.addError(error);
}
}
use of org.springframework.validation.ObjectError in project head by mifos.
the class PreviewModifyCoaController method processFormSubmit.
@RequestMapping(method = RequestMethod.POST)
public ModelAndView processFormSubmit(@RequestParam(value = EDIT_PARAM, required = false) String edit, @RequestParam(value = CANCEL_PARAM, required = false) String cancel, @ModelAttribute("formBean") CoaFormBean formBean, BindingResult result, SessionStatus status) {
ModelAndView mav = new ModelAndView(REDIRECT_TO_COA_ADMIN_SCREEN);
if (StringUtils.isNotBlank(edit)) {
mav = new ModelAndView(MODIFY_COA);
mav.addObject("formBean", formBean);
mav.addObject("COAlist", coaServiceFacade.getList(null));
} else if (StringUtils.isNotBlank(cancel)) {
status.setComplete();
} else if (result.hasErrors()) {
mav = new ModelAndView(PREVIEW_MODIFY_COA);
} else {
try {
CoaDto coaDto = new CoaDto();
coaDto.setAccountId(formBean.getAccountId());
coaDto.setAccountName(formBean.getCoaName());
coaDto.setGlCodeString(formBean.getGlCode());
coaDto.setParentGlCode(formBean.getParentGlCode());
coaServiceFacade.modify(coaDto);
status.setComplete();
} catch (BusinessRuleException ex) {
ObjectError error = new ObjectError("formBean", new String[] { ex.getMessageKey() }, new Object[] {}, "default: ");
result.addError(error);
mav.setViewName(PREVIEW_MODIFY_COA);
mav.addObject("formBean", formBean);
}
}
return mav;
}
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);
}
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();
}
}
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);
}
Aggregations