Search in sources :

Example 41 with ObjectError

use of org.springframework.validation.ObjectError in project head by mifos.

the class SavingsProductPreviewController method handleBusinessRuleViolation.

private void handleBusinessRuleViolation(String editFormview, SavingsProductFormBean savingsProduct, BindingResult result, ModelAndView modelAndView, String messageKey) {
    ObjectError error = new ObjectError("savingsProduct", new String[] { messageKey }, new Object[] {}, "Error: Problem persisting savings product.");
    result.addError(error);
    configurationDto = this.configurationServiceFacade.getAccountingConfiguration();
    modelAndView.addObject("GLCodeMode", configurationDto.getGlCodeMode());
    modelAndView.setViewName("previewSavingsProducts");
    modelAndView.addObject("savingsProduct", savingsProduct);
    modelAndView.addObject("editFormview", editFormview);
    populateModelAndViewForPreview(savingsProduct, modelAndView);
}
Also used : ObjectError(org.springframework.validation.ObjectError)

Example 42 with ObjectError

use of org.springframework.validation.ObjectError in project head by mifos.

the class LoanProductFormBeanValidator method convertLoanAmountByLastLoanJsr303ViolationsToSpringErrors.

private void convertLoanAmountByLastLoanJsr303ViolationsToSpringErrors(BindingResult result, int lastLoanRow, ByLastLoanAmountBean byLoanCycle, Set<ConstraintViolation<ByLastLoanAmountBean>> cycleViolations) {
    for (ConstraintViolation<ByLastLoanAmountBean> constraintViolation : cycleViolations) {
        ObjectError error = new ObjectError("loanProduct", new String[] { buildViolationMessage("loanProduct.loanAmountByLastLoanAmount", constraintViolation) }, new Object[] { lastLoanRow + 1 }, constraintViolation.getMessage());
        result.addError(error);
    }
    if (cycleViolations.isEmpty() && !byLoanCycle.isRangeValid()) {
        ObjectError error = new ObjectError("loanProduct", new String[] { "Max.loanProduct.loanAmountByLastLoanAmount.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.loanAmountByLastLoanAmount.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.loanAmountByLastLoanAmount.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 43 with ObjectError

use of org.springframework.validation.ObjectError in project head by mifos.

the class LoanProductFormBeanValidator method convertInstallmentsByLoanCycleJsr303ViolationsToSpringErrors.

private void convertInstallmentsByLoanCycleJsr303ViolationsToSpringErrors(BindingResult result, int loanCycleRow, ByLoanCycleBean byLoanCycle, Set<ConstraintViolation<ByLoanCycleBean>> cycleViolations) {
    for (ConstraintViolation<ByLoanCycleBean> constraintViolation : cycleViolations) {
        ObjectError error = new ObjectError("loanProduct", new String[] { buildViolationMessage("loanProduct.installmentsByLoanCycle", constraintViolation) }, new Object[] { loanCycleRow + 1 }, constraintViolation.getMessage());
        result.addError(error);
    }
    if (cycleViolations.isEmpty() && !byLoanCycle.minIsLessThanMax()) {
        ObjectError error = new ObjectError("loanProduct", new String[] { "Max.loanProduct.installmentsByLoanCycle.max" }, new Object[] { loanCycleRow + 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.installmentsByLoanCycle.theDefault" }, new Object[] { loanCycleRow + 1 }, "The default is not within min and max range.");
        result.addError(error);
    }
}
Also used : ObjectError(org.springframework.validation.ObjectError)

Example 44 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 45 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)

Aggregations

ObjectError (org.springframework.validation.ObjectError)57 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 BindException (org.springframework.validation.BindException)10 FieldError (org.springframework.validation.FieldError)8 BusinessRuleException (org.mifos.service.BusinessRuleException)7 ModelAndView (org.springframework.web.servlet.ModelAndView)7 BindingResult (org.springframework.validation.BindingResult)6 DocumentBuilder (javax.xml.parsers.DocumentBuilder)5 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)5 Test (org.junit.Test)5 OnmsLocationMonitor (org.opennms.netmgt.model.OnmsLocationMonitor)5 LocationMonitorIdCommand (org.opennms.web.svclayer.model.LocationMonitorIdCommand)5 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)5 MapBindingResult (org.springframework.validation.MapBindingResult)5 Document (org.w3c.dom.Document)5 Element (org.w3c.dom.Element)5 ArrayList (java.util.ArrayList)3 Errors (org.springframework.validation.Errors)3 MethodArgumentNotValidException (org.springframework.web.bind.MethodArgumentNotValidException)3 ServletException (javax.servlet.ServletException)2