@Test public final void testProcessSave() { try { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); TargetGroup group = manager.loadGroup(15000L); GroupsEditorContext context = new GroupsEditorContext(group, true); request.getSession().setAttribute( TabbedGroupController.EDITOR_CONTEXT, context); DefaultCommand comm = new DefaultCommand(); comm.setMode(DefaultCommand.MODE_EDIT); comm.setTargetGroupOid(15000L); Tab currTab = testInstance.getTabConfig().getTabs().get(0); assertTrue(currTab != null); BindException aError = new BindException(new DefaultCommand(), null); testInstance.showForm(request, response, comm, aError); context = testInstance.getEditorContext(request); context.getTargetGroup().setName("Test Group"); ModelAndView mav = testInstance.processSave(currTab, request, response, comm, aError); assertTrue(mav != null); assertTrue(mav.getViewName().equals("groups-search")); assertTrue(mav.getModel().get("page_message") != null); assertTrue(((String) mav.getModel().get("page_message")) .startsWith("group.saved")); } catch (Exception e) { String message = e.getClass().toString() + " - " + e.getMessage(); log.debug(message); fail(message); } }
@Override protected ModelAndView processSave(Tab currentTab, HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) { GroupsEditorContext ctx = getEditorContext(req); TargetGroup group = ctx.getTargetGroup(); if(!targetManager.isNameOk(group)) { errors.reject("target.errors.duplicatename"); } if(errors.hasErrors()) { TabbedModelAndView tmav = currentTab.getTabHandler().preProcessNextTab(this, currentTab, req, res, comm ,errors); tmav.getTabStatus().setCurrentTab(currentTab); tmav.addObject(Constants.GBL_CMD_DATA, comm); tmav.addObject(Constants.GBL_ERRORS, errors); return tmav; } else { try { targetManager.save(ctx.getTargetGroup(), ctx.getParents()); ModelAndView mav = searchController.prepareSearchView(req, res, errors); mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("group.saved", new Object[] { ctx.getTargetGroup().getName() }, Locale.getDefault())); unbindEditorContext(req); return mav; } catch(DataIntegrityViolationException ex) { errors.reject("target.errors.duplicatename"); Tab tab = getTabConfig().getTabByID("GENERAL"); TabbedModelAndView tmav = tab.getTabHandler().preProcessNextTab(this, tab, req, res, comm ,errors); tmav.getTabStatus().setCurrentTab(tab); tmav.addObject(Constants.GBL_ERRORS, errors); return tmav; } } }
TabbedGroupController extends TabbedController { @Override protected ModelAndView processSave(Tab currentTab, HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) { GroupsEditorContext ctx = getEditorContext(req); TargetGroup group = ctx.getTargetGroup(); if(!targetManager.isNameOk(group)) { errors.reject("target.errors.duplicatename"); } if(errors.hasErrors()) { TabbedModelAndView tmav = currentTab.getTabHandler().preProcessNextTab(this, currentTab, req, res, comm ,errors); tmav.getTabStatus().setCurrentTab(currentTab); tmav.addObject(Constants.GBL_CMD_DATA, comm); tmav.addObject(Constants.GBL_ERRORS, errors); return tmav; } else { try { targetManager.save(ctx.getTargetGroup(), ctx.getParents()); ModelAndView mav = searchController.prepareSearchView(req, res, errors); mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("group.saved", new Object[] { ctx.getTargetGroup().getName() }, Locale.getDefault())); unbindEditorContext(req); return mav; } catch(DataIntegrityViolationException ex) { errors.reject("target.errors.duplicatename"); Tab tab = getTabConfig().getTabByID("GENERAL"); TabbedModelAndView tmav = tab.getTabHandler().preProcessNextTab(this, tab, req, res, comm ,errors); tmav.getTabStatus().setCurrentTab(tab); tmav.addObject(Constants.GBL_ERRORS, errors); return tmav; } } } }
TabbedGroupController extends TabbedController { @Override protected ModelAndView processSave(Tab currentTab, HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) { GroupsEditorContext ctx = getEditorContext(req); TargetGroup group = ctx.getTargetGroup(); if(!targetManager.isNameOk(group)) { errors.reject("target.errors.duplicatename"); } if(errors.hasErrors()) { TabbedModelAndView tmav = currentTab.getTabHandler().preProcessNextTab(this, currentTab, req, res, comm ,errors); tmav.getTabStatus().setCurrentTab(currentTab); tmav.addObject(Constants.GBL_CMD_DATA, comm); tmav.addObject(Constants.GBL_ERRORS, errors); return tmav; } else { try { targetManager.save(ctx.getTargetGroup(), ctx.getParents()); ModelAndView mav = searchController.prepareSearchView(req, res, errors); mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("group.saved", new Object[] { ctx.getTargetGroup().getName() }, Locale.getDefault())); unbindEditorContext(req); return mav; } catch(DataIntegrityViolationException ex) { errors.reject("target.errors.duplicatename"); Tab tab = getTabConfig().getTabByID("GENERAL"); TabbedModelAndView tmav = tab.getTabHandler().preProcessNextTab(this, tab, req, res, comm ,errors); tmav.getTabStatus().setCurrentTab(tab); tmav.addObject(Constants.GBL_ERRORS, errors); return tmav; } } }  }
TabbedGroupController extends TabbedController { @Override protected ModelAndView processSave(Tab currentTab, HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) { GroupsEditorContext ctx = getEditorContext(req); TargetGroup group = ctx.getTargetGroup(); if(!targetManager.isNameOk(group)) { errors.reject("target.errors.duplicatename"); } if(errors.hasErrors()) { TabbedModelAndView tmav = currentTab.getTabHandler().preProcessNextTab(this, currentTab, req, res, comm ,errors); tmav.getTabStatus().setCurrentTab(currentTab); tmav.addObject(Constants.GBL_CMD_DATA, comm); tmav.addObject(Constants.GBL_ERRORS, errors); return tmav; } else { try { targetManager.save(ctx.getTargetGroup(), ctx.getParents()); ModelAndView mav = searchController.prepareSearchView(req, res, errors); mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("group.saved", new Object[] { ctx.getTargetGroup().getName() }, Locale.getDefault())); unbindEditorContext(req); return mav; } catch(DataIntegrityViolationException ex) { errors.reject("target.errors.duplicatename"); Tab tab = getTabConfig().getTabByID("GENERAL"); TabbedModelAndView tmav = tab.getTabHandler().preProcessNextTab(this, tab, req, res, comm ,errors); tmav.getTabStatus().setCurrentTab(tab); tmav.addObject(Constants.GBL_ERRORS, errors); return tmav; } } }  void bindEditorContext(HttpServletRequest req, GroupsEditorContext context); void unbindEditorContext(HttpServletRequest req); GroupsEditorContext getEditorContext(HttpServletRequest req); void setTargetManager(TargetManager targetManager); void setBusinessObjectFactory(BusinessObjectFactory businessObjectFactory); void setSearchController(GroupSearchController searchController); void setMessageSource(MessageSource messageSource); void setAuthorityManager(AuthorityManager authorityManager); }
TabbedGroupController extends TabbedController { @Override protected ModelAndView processSave(Tab currentTab, HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) { GroupsEditorContext ctx = getEditorContext(req); TargetGroup group = ctx.getTargetGroup(); if(!targetManager.isNameOk(group)) { errors.reject("target.errors.duplicatename"); } if(errors.hasErrors()) { TabbedModelAndView tmav = currentTab.getTabHandler().preProcessNextTab(this, currentTab, req, res, comm ,errors); tmav.getTabStatus().setCurrentTab(currentTab); tmav.addObject(Constants.GBL_CMD_DATA, comm); tmav.addObject(Constants.GBL_ERRORS, errors); return tmav; } else { try { targetManager.save(ctx.getTargetGroup(), ctx.getParents()); ModelAndView mav = searchController.prepareSearchView(req, res, errors); mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("group.saved", new Object[] { ctx.getTargetGroup().getName() }, Locale.getDefault())); unbindEditorContext(req); return mav; } catch(DataIntegrityViolationException ex) { errors.reject("target.errors.duplicatename"); Tab tab = getTabConfig().getTabByID("GENERAL"); TabbedModelAndView tmav = tab.getTabHandler().preProcessNextTab(this, tab, req, res, comm ,errors); tmav.getTabStatus().setCurrentTab(tab); tmav.addObject(Constants.GBL_ERRORS, errors); return tmav; } } }  void bindEditorContext(HttpServletRequest req, GroupsEditorContext context); void unbindEditorContext(HttpServletRequest req); GroupsEditorContext getEditorContext(HttpServletRequest req); void setTargetManager(TargetManager targetManager); void setBusinessObjectFactory(BusinessObjectFactory businessObjectFactory); void setSearchController(GroupSearchController searchController); void setMessageSource(MessageSource messageSource); void setAuthorityManager(AuthorityManager authorityManager); static final String EDITOR_CONTEXT; }