Search in sources :

Example 61 with ObjectError

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);
    }
}
Also used : ObjectError(org.springframework.validation.ObjectError)

Example 62 with ObjectError

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;
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) ObjectError(org.springframework.validation.ObjectError) CoaDto(org.mifos.application.admin.servicefacade.CoaDto) ModelAndView(org.springframework.web.servlet.ModelAndView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 63 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 64 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 65 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)

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