Search in sources :

Example 1 with ObjectError

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

the class NewFundPreviewController 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") FundFormBean formBean, BindingResult result, SessionStatus status) {
    ModelAndView mav = new ModelAndView(REDIRECT_TO_ADMIN_SCREEN);
    if (StringUtils.isNotBlank(edit)) {
        mav = new ModelAndView("editFunds");
        mav.addObject("formBean", formBean);
        mav.addObject("previewView", "newFundPreview");
    } else if (StringUtils.isNotBlank(cancel)) {
        mav = new ModelAndView(REDIRECT_TO_VIEW_FUNDS);
        status.setComplete();
    } else if (result.hasErrors()) {
        mav = new ModelAndView("newFundPreview");
    } else {
        FundCodeDto codeDto = new FundCodeDto();
        codeDto.setId(formBean.getCodeId());
        codeDto.setValue(formBean.getCodeValue());
        FundDto fundDto = new FundDto();
        fundDto.setCode(codeDto);
        fundDto.setId(formBean.getId());
        fundDto.setName(formBean.getName());
        try {
            this.fundServiceFacade.createFund(fundDto);
            status.setComplete();
        } catch (BusinessRuleException e) {
            ObjectError error = new ObjectError("formBean", new String[] { e.getMessageKey() }, new Object[] {}, "default: ");
            result.addError(error);
            mav.setViewName("newFundPreview");
            mav.addObject("formBean", formBean);
        }
    }
    return mav;
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) ObjectError(org.springframework.validation.ObjectError) ModelAndView(org.springframework.web.servlet.ModelAndView) FundDto(org.mifos.accounts.fund.servicefacade.FundDto) FundCodeDto(org.mifos.accounts.fund.servicefacade.FundCodeDto) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ObjectError

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

the class PreviewCoaController 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) {
    String viewName = REDIRECT_TO_COA_ADMIN_SCREEN;
    ModelAndView modelAndView = new ModelAndView();
    if (StringUtils.isNotBlank(edit)) {
        viewName = DEFINE_NEW_COA;
        modelAndView.setViewName(viewName);
        modelAndView.addObject("formBean", formBean);
    } else if (StringUtils.isNotBlank(cancel)) {
        modelAndView.setViewName(REDIRECT_TO_COA_ADMIN_SCREEN);
        status.setComplete();
    } else if (result.hasErrors()) {
        modelAndView.setViewName(PREVIEW_COA);
    } else {
        try {
            CoaDto coaDto = new CoaDto();
            coaDto.setAccountName(formBean.getCoaName());
            coaDto.setGlCodeString(formBean.getGlCode());
            coaDto.setParentId(formBean.getParentId());
            coaServiceFacade.create(coaDto);
            viewName = REDIRECT_TO_COA_ADMIN_SCREEN;
            modelAndView.setViewName(viewName);
            status.setComplete();
        } catch (BusinessRuleException e) {
            ObjectError error = new ObjectError("formBean", new String[] { e.getMessageKey() }, new Object[] {}, "default: ");
            result.addError(error);
            modelAndView.setViewName(PREVIEW_COA);
            modelAndView.addObject("formBean", formBean);
        }
    }
    return modelAndView;
}
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 3 with ObjectError

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

the class ProductCategoryPreviewController 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") ProductCategoryFormBean formBean, BindingResult result) {
    String viewName = REDIRECT_TO_ADMIN_SCREEN;
    ModelAndView modelAndView = new ModelAndView();
    if (StringUtils.isNotBlank(edit)) {
        viewName = "editCategoryInformation";
        modelAndView.setViewName(viewName);
        modelAndView.addObject("formBean", formBean);
        modelAndView.addObject("breadcrumbs", new AdminBreadcrumbBuilder().withLink("admin.viewproductcategories", "viewProductCategories.ftl").withLink(formBean.getProductCategoryName(), "").build());
    } else if (StringUtils.isNotBlank(cancel)) {
        viewName = REDIRECT_TO_ADMIN_SCREEN;
        modelAndView.setViewName(viewName);
    } else if (result.hasErrors()) {
        viewName = "categoryPreview";
        modelAndView.setViewName(viewName);
        modelAndView.addObject("formBean", formBean);
        modelAndView.addObject("breadcrumbs", new AdminBreadcrumbBuilder().withLink("admin.viewproductcategories", "viewProductCategories.ftl").withLink(formBean.getProductCategoryName(), "").build());
    } else {
        Integer productStatusId = Integer.parseInt(formBean.getProductCategoryStatusId());
        Integer productTypeId = Integer.parseInt(formBean.getProductTypeId());
        CreateOrUpdateProductCategory productCategory = new CreateOrUpdateProductCategory(productTypeId.shortValue(), formBean.getProductCategoryName(), formBean.getProductCategoryDesc(), productStatusId.shortValue(), formBean.getGlobalPrdCategoryNum());
        try {
            this.adminServiceFacade.updateProductCategory(productCategory);
            modelAndView.setViewName(REDIRECT_TO_ADMIN_SCREEN);
        } catch (BusinessRuleException e) {
            ObjectError error = new ObjectError("formBean", new String[] { e.getMessageKey() }, new Object[] {}, "default: ");
            result.addError(error);
            modelAndView.setViewName("categoryPreview");
            modelAndView.addObject("formBean", formBean);
            modelAndView.addObject("breadcrumbs", new AdminBreadcrumbBuilder().withLink("admin.viewproductcategories", "viewProductCategories.ftl").withLink(formBean.getProductCategoryName(), "").build());
        }
    }
    return modelAndView;
}
Also used : CreateOrUpdateProductCategory(org.mifos.dto.domain.CreateOrUpdateProductCategory) BusinessRuleException(org.mifos.service.BusinessRuleException) ObjectError(org.springframework.validation.ObjectError) ModelAndView(org.springframework.web.servlet.ModelAndView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with ObjectError

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

the class SavingsProductValidator method validateGroup.

public void validateGroup(SavingsProductFormBean savingsProductFormBean, BindingResult result) {
    if (savingsProductFormBean.isGroupSavingAccount() && StringUtils.isBlank(savingsProductFormBean.getSelectedGroupSavingsApproach())) {
        ObjectError error = new ObjectError("savingsProduct", new String[] { "NotEmpty.savingsProduct.selectedGroupSavingsApproach" }, new Object[] {}, "default: ");
        result.addError(error);
    }
}
Also used : ObjectError(org.springframework.validation.ObjectError)

Example 5 with ObjectError

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

the class SavingsProductValidator method validateManadtorySavingsProduct.

public void validateManadtorySavingsProduct(SavingsProductFormBean savingsProductFormBean, BindingResult result) {
    if (savingsProductFormBean.isMandatory() && savingsProductFormBean.getAmountForDeposit() == null || savingsProductFormBean.getAmountForDeposit().intValue() <= 0) {
        ObjectError error = new ObjectError("savingsProduct", new String[] { "Min.savingsProduct.amountForDesposit" }, new Object[] {}, "default: ");
        result.addError(error);
    }
}
Also used : ObjectError(org.springframework.validation.ObjectError)

Aggregations

ObjectError (org.springframework.validation.ObjectError)98 FieldError (org.springframework.validation.FieldError)19 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)17 BindException (org.springframework.validation.BindException)14 BindingResult (org.springframework.validation.BindingResult)14 ArrayList (java.util.ArrayList)12 Test (org.junit.jupiter.api.Test)12 MapBindingResult (org.springframework.validation.MapBindingResult)11 ModelAndView (org.springframework.web.servlet.ModelAndView)10 BusinessRuleException (org.mifos.service.BusinessRuleException)6 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)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 File (java.io.File)4