use of org.springframework.validation.FieldError in project head by mifos.
the class LoanRepaymentFormBean method validateEnterLoanRepaymentDetails.
public void validateEnterLoanRepaymentDetails(ValidationContext context) {
MessageContext messageContext = context.getMessageContext();
Errors errors = validator.checkConstraints(this);
if (errors.hasErrors()) {
for (FieldError fieldError : errors.getFieldErrors()) {
String arg = "";
if ("paymentAmount".equals(fieldError.getField())) {
arg = "Amount";
}
messageContext.addMessage(buildValidationMessage("errors.mandatory", fieldError.getField(), arg));
}
}
if (dateValidator == null) {
dateValidator = new DateValidator();
}
//payment date validation
if (!dateValidator.formsValidDate(paymentDateDD, paymentDateMM, paymentDateYY)) {
messageContext.addMessage(buildValidationMessage("errors.invaliddate", "paymentDate", "accounts.date_of_trxn"));
} else if (getPaymentDate().isAfter(new LocalDate())) {
messageContext.addMessage(buildValidationMessage("errors.futuredate", "paymentDate", "accounts.date_of_trxn"));
} else if (getPaymentDate().isBefore(lastPaymentDate)) {
messageContext.addMessage(buildValidationMessage("errors.payment.date.before.last.payment", "paymentDate", "accounts.date_of_trxn"));
}
//receipt date validation
if (isReceiptDateSpecified() && !dateValidator.formsValidDate(receiptDateDD, receiptDateMM, receiptDateYY)) {
messageContext.addMessage(buildValidationMessage("errors.invaliddate", "receiptDate", "accounts.receiptdate"));
}
//amount validation
if (paymentAmount != null && paymentAmount.doubleValue() <= 0) {
messageContext.addMessage(buildValidationMessage("error.penalty.incorrectDouble", "paymentAmount", "Amount"));
}
if (messageContext.hasErrorMessages()) {
this.truePrintReceipt = this.printReceipt;
this.printReceipt = false;
}
}
use of org.springframework.validation.FieldError in project head by mifos.
the class PentahoReportingController method addErrorToBindingResult.
private void addErrorToBindingResult(PentahoValidationError validationError, BindingResult bindingResult) {
ObjectError error;
if (validationError.isFieldError()) {
error = new FieldError("pentahoReportFormBean", validationError.getParamName(), validationError.getParamName() + ": " + validationError.getErrorMessage());
} else {
error = new ObjectError("pentahoReportFormBean", validationError.getErrorMessage());
}
bindingResult.addError(error);
}
use of org.springframework.validation.FieldError 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.FieldError in project spring-boot by spring-projects.
the class RelaxedDataBinderTests method testRequiredFieldsValidation.
@Test
public void testRequiredFieldsValidation() throws Exception {
TargetWithValidatedMap target = new TargetWithValidatedMap();
BindingResult result = bind(target, "info[foo]: bar");
assertThat(result.getErrorCount()).isEqualTo(2);
for (FieldError error : result.getFieldErrors()) {
System.err.println(new StaticMessageSource().getMessage(error, Locale.getDefault()));
}
}
use of org.springframework.validation.FieldError in project ArachneCentralAPI by OHDSI.
the class BaseSkillController method create.
@ApiOperation("Register new skill.")
@RequestMapping(value = "/api/v1/user-management/skills", method = RequestMethod.POST)
public JsonResult<SkillDTO> create(@RequestBody @Valid SkillDTO skillDTO, BindingResult binding) throws NotExistException, NotUniqueException, PermissionDeniedException {
JsonResult<SkillDTO> result;
if (binding.hasErrors()) {
result = new JsonResult<>(JsonResult.ErrorCode.VALIDATION_ERROR);
for (FieldError fieldError : binding.getFieldErrors()) {
result.getValidatorErrors().put(fieldError.getField(), fieldError.getDefaultMessage());
}
} else {
S skill = convertDtoToSkill(skillDTO);
skill = skillService.create(skill);
result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
result.setResult(conversionService.convert(skill, SkillDTO.class));
}
return result;
}
Aggregations