use of org.mifos.dto.domain.CreateOrUpdateProductCategory 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;
}
use of org.mifos.dto.domain.CreateOrUpdateProductCategory in project head by mifos.
the class DefineProductCategoryPreviewController method processFormSubmit.
@RequestMapping(method = RequestMethod.POST)
public ModelAndView processFormSubmit(@RequestParam(value = CANCEL_PARAM, required = false) String cancel, @RequestParam(value = EDIT_PARAM, required = false) String edit, @ModelAttribute("formBean") ProductCategoryFormBean bean, BindingResult result) {
ModelAndView modelAndView = new ModelAndView("defineNewCategory");
if (StringUtils.isNotBlank(cancel)) {
modelAndView.setViewName(REDIRECT_TO_ADMIN);
} else if (StringUtils.isNotBlank(edit)) {
modelAndView.setViewName("defineNewCategory");
modelAndView.addObject("formBean", bean);
modelAndView.addObject("typeList", this.getProductCategoryTypes());
} else if (result.hasErrors()) {
modelAndView.setViewName("newProductCategoryPreview");
modelAndView.addObject("formBean", bean);
} else {
CreateOrUpdateProductCategory productCategory = new CreateOrUpdateProductCategory(Short.parseShort(bean.getProductTypeId()), bean.getProductCategoryName(), bean.getProductCategoryDesc(), Short.parseShort(bean.getProductCategoryStatusId()), bean.getGlobalPrdCategoryNum());
try {
this.adminServiceFacade.createProductCategory(productCategory);
modelAndView.setViewName(REDIRECT_TO_ADMIN);
} catch (BusinessRuleException e) {
ObjectError error = new ObjectError("formBean", new String[] { e.getMessageKey() }, new Object[] {}, "default: ");
result.addError(error);
modelAndView.setViewName("newProductCategoryPreview");
modelAndView.addObject("formBean", bean);
}
}
return modelAndView;
}
Aggregations