Search in sources :

Example 6 with ObjectError

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

the class LoanProductFormBeanValidator method convertInstallmentsSameForAllLoansJsr303ViolationsToSpringErrors.

private void convertInstallmentsSameForAllLoansJsr303ViolationsToSpringErrors(BindingResult result, SameForAllLoanBean sameForAllLoanBean, Set<ConstraintViolation<SameForAllLoanBean>> violations) {
    for (ConstraintViolation<SameForAllLoanBean> constraintViolation : violations) {
        ObjectError error = new ObjectError("loanProduct", new String[] { buildViolationMessage("loanProduct.installmentsSameForAllLoans", constraintViolation) }, new Object[] {}, constraintViolation.getMessage());
        result.addError(error);
    }
    if (violations.isEmpty() && !sameForAllLoanBean.minIsLessThanMax()) {
        ObjectError error = new ObjectError("loanProduct", new String[] { "Max.loanProduct.installmentsSameForAllLoans.max" }, new Object[] {}, "The min must be less than max.");
        result.addError(error);
    }
    if (violations.isEmpty() && !sameForAllLoanBean.defaultIsBetweenMinAndMax()) {
        ObjectError error = new ObjectError("loanProduct", new String[] { "Max.loanProduct.installmentsSameForAllLoans.theDefault" }, new Object[] {}, "The default is not within min and max range.");
        result.addError(error);
    }
}
Also used : ObjectError(org.springframework.validation.ObjectError)

Example 7 with ObjectError

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

the class LoanProductFormBeanValidator method convertLoanAmountByLoanCycleJsr303ViolationsToSpringErrors.

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

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

the class LoanProductFormBeanValidator method validateInterestRateRange.

private void validateInterestRateRange(LoanProductFormBean loanProductFormBean, BindingResult result) {
    if (!result.hasErrors()) {
        if (loanProductFormBean.getMinInterestRate() > loanProductFormBean.getMaxInterestRate()) {
            ObjectError error = new ObjectError("loanProduct", new String[] { "Range.loanProduct.maxInterestRate" }, new Object[] {}, "The min must be less than max.");
            result.addError(error);
        }
        if (loanProductFormBean.getDefaultInterestRate() < loanProductFormBean.getMinInterestRate() || loanProductFormBean.getDefaultInterestRate() > loanProductFormBean.getMaxInterestRate()) {
            ObjectError error = new ObjectError("loanProduct", new String[] { "Range.loanProduct.defaultInterestRate" }, new Object[] {}, "The min must be less than max.");
            result.addError(error);
        }
    }
}
Also used : ObjectError(org.springframework.validation.ObjectError)

Example 9 with ObjectError

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

the class LoanProductFormBeanValidator method convertLoanAmountSameForAllLoansJsr303ViolationsToSpringErrors.

private void convertLoanAmountSameForAllLoansJsr303ViolationsToSpringErrors(BindingResult result, SameForAllLoanBean sameForAllLoanBean, Set<ConstraintViolation<SameForAllLoanBean>> violations) {
    for (ConstraintViolation<SameForAllLoanBean> constraintViolation : violations) {
        ObjectError error = new ObjectError("loanProduct", new String[] { buildViolationMessage("loanProduct.sameForAllLoans", constraintViolation) }, new Object[] {}, constraintViolation.getMessage());
        result.addError(error);
    }
    if (violations.isEmpty() && !sameForAllLoanBean.minIsLessThanMax()) {
        ObjectError error = new ObjectError("loanProduct", new String[] { "Max.loanProduct.sameForAllLoans.max" }, new Object[] {}, "The min must be less than max.");
        result.addError(error);
    }
    if (violations.isEmpty() && !sameForAllLoanBean.defaultIsBetweenMinAndMax()) {
        ObjectError error = new ObjectError("loanProduct", new String[] { "Max.loanProduct.sameForAllLoans.theDefault" }, new Object[] {}, "The default is not within min and max range.");
        result.addError(error);
    }
}
Also used : ObjectError(org.springframework.validation.ObjectError)

Example 10 with ObjectError

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

the class ChangePasswordController method processFormSubmit.

@RequestMapping(method = RequestMethod.POST)
public String processFormSubmit(@RequestParam(value = CANCEL_PARAM, required = false) String cancel, @ModelAttribute("formBean") @Valid ChangePasswordFormBean formBean, BindingResult result, SessionStatus status, HttpServletRequest request) {
    String viewName = HOME_PAGE;
    if (CANCEL_PARAM_VALUE.equals(cancel)) {
        viewName = REDIRECT_AND_LOGOUT;
        status.setComplete();
    } else if (result.hasErrors()) {
        viewName = "changePassword";
    } else {
        try {
            ChangePasswordRequest changePasswordRequest = new ChangePasswordRequest(formBean.getUsername(), formBean.getOldPassword(), formBean.getNewPassword());
            loginServiceFacade.changePassword(changePasswordRequest);
            status.setComplete();
        } catch (BusinessRuleException e) {
            ObjectError error = new ObjectError("passwordUsed", messageSource.getMessage("error.passwordAlreadyUsedException", null, RequestContextUtils.getLocale(request)));
            result.addError(error);
            viewName = "changePassword";
        }
    }
    return viewName;
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) ObjectError(org.springframework.validation.ObjectError) ChangePasswordRequest(org.mifos.dto.domain.ChangePasswordRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ObjectError (org.springframework.validation.ObjectError)55 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 Errors (org.springframework.validation.Errors)3 MethodArgumentNotValidException (org.springframework.web.bind.MethodArgumentNotValidException)3 ArrayList (java.util.ArrayList)2 ServletException (javax.servlet.ServletException)2