List of usage examples for org.springframework.web.servlet ModelAndView getModel
public Map<String, Object> getModel()
From source file:org.springjutsu.validation.mvc.SuccessViewHandlerInterceptor.java
/** * Responsible for redirecting to the view defined * in the @link{SuccessView} annotation on the current * handler method.//w ww .ja va2s . co m * In the event that there are multiple possible * success paths defined for the success view, * will attempt to isolate the closest matching * url-path key and redirect to the value path, * as described in @link{SuccessView} */ @Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) { if (!(handler instanceof HandlerMethod)) { return; } SuccessViews successViews = (SuccessViews) ((HandlerMethod) handler) .getMethodAnnotation(SuccessViews.class); SuccessView successView = (SuccessView) ((HandlerMethod) handler).getMethodAnnotation(SuccessView.class); String viewName = null; if (successView != null) { viewName = successView.value(); } else if (successViews != null) { String[] controllerPaths = RequestUtils.getControllerRequestPaths((HandlerMethod) handler); viewName = findMatchingTargetUrl(successViews.value(), controllerPaths, request); } if (viewName == null) { return; } viewName = RequestUtils.replaceRestPathVariables(viewName, modelAndView.getModel(), request); modelAndView.setViewName(viewName); }
From source file:com.thoughtworks.go.server.controller.ArtifactsControllerIntegrationTest.java
@Test public void shouldHaveJobIdentifierInModelForHtmlFolderView() throws Exception { ModelAndView mav = artifactsController.getArtifactAsHtml(pipeline.getName(), pipeline.getLabel(), stage.getName(), String.valueOf(stage.getCounter()), job.getName(), "", null, null); assertThat(mav.getModel().get("jobIdentifier"), is(new JobIdentifier(pipeline, stage, job))); assertThat(mav.getViewName(), is("rest/html")); }
From source file:com.zb.app.web.controller.manage.ManageController.java
@RequestMapping(value = "/blacklistsview.htm") public ModelAndView blacklistsview(ModelAndView mav, TravelBlackListQuery query, Integer page, Long id) { query.setPageSize(100);/*from w ww. j a va2 s. c o m*/ query.setNowPageIndex(Argument.isNotPositive(page) ? 0 : page - 1); query.setBeCId(id); PaginationList<TravelBlackListFullDO> list = companyService.listPagination(query, new DefaultIpageUrl()); mav.getModel().put(CustomVelocityLayoutView.USE_LAYOUT, "false"); mav.addObject("blackList", list); mav.addObject("pagination", list.getQuery()); mav.setViewName("/manage/blacklists/view"); return mav; }
From source file:debrepo.teamcity.web.DebDownloadController.java
private ModelAndView servePackagesFile(HttpServletRequest request, HttpServletResponse response, List<? extends DebPackage> packages) { response.setContentType("text/plain"); final ModelAndView mv = new ModelAndView( myPluginDescriptor.getPluginResourcesPath("debRepository/packages.jsp")); mv.getModel().put("packages", packages); Loggers.SERVER.info("DebDownloadController:: Returning 200 : Packages file exists with the name: " + request.getPathInfo());//from ww w .jav a 2 s . c o m return mv; }
From source file:com.thoughtworks.go.server.controller.GoConfigAdministrationControllerIntegrationTest.java
@Test public void shouldPostStageAsPartialXml() throws Exception { configHelper.addPipeline("pipeline", "stage", "build1", "build2"); String newXml = NEW_STAGE;/*from w ww. j a v a 2 s .com*/ String md5 = goConfigFileDao.md5OfConfigFile(); ModelAndView mav = controller.postStageAsXmlPartial("pipeline", 0, newXml, md5, response); assertThat(response.getStatus(), is(SC_OK)); assertThat(response.getContentType(), is(RESPONSE_CHARSET_JSON)); Json json = (Json) mav.getModel().get("json"); new JsonTester(json).shouldContain("{ 'result' : 'Stage changed successfully.' }"); }
From source file:com.thoughtworks.go.server.controller.GoConfigAdministrationControllerIntegrationTest.java
@Test public void shouldPostPipelineAsPartialXml() throws Exception { configHelper.addPipeline("pipeline", "stage", "build1", "build2"); String newXml = NEW_PIPELINE; String md5 = goConfigFileDao.md5OfConfigFile(); groupName = BasicPipelineConfigs.DEFAULT_GROUP; ModelAndView mav = controller.postPipelineAsXmlPartial(0, groupName, newXml, md5, response); assertThat(response.getStatus(), is(SC_OK)); assertThat(response.getContentType(), is(RESPONSE_CHARSET_JSON)); Json json = (Json) mav.getModel().get("json"); new JsonTester(json).shouldContain("{ 'result' : 'Pipeline changed successfully.' }"); }
From source file:com.thoughtworks.go.server.controller.GoConfigAdministrationControllerIntegrationTest.java
@Test public void shouldReturnXmlAndErrorMessageWhenPostOfStageAsInvalidPartialXml() throws Exception { configHelper.addPipeline("pipeline", "stage", "build1", "build2"); String badXml = "<;askldjfa;dsklfja;sdjas;lkdf"; String md5 = goConfigFileDao.md5OfConfigFile(); ModelAndView mav = controller.postStageAsXmlPartial("pipeline", 0, badXml, md5, response); assertThat(response.getStatus(), is(SC_CONFLICT)); assertThat(response.getContentType(), is(RESPONSE_CHARSET_JSON)); Json json = (Json) mav.getModel().get("json"); new JsonTester(json).shouldContain( "{ 'result' : 'Error on line 1 of document : The markup in the document preceding the root element must be well-formed. Nested exception: The markup in the document preceding the root element must be well-formed.'," + " 'originalContent' : '" + badXml + "' }"); }
From source file:com.thoughtworks.go.server.controller.GoConfigAdministrationControllerIntegrationTest.java
@Test public void shouldPostBuildAsPartialXml() throws Exception { configHelper.addPipeline("pipeline", "stage", "build1", "build2"); String newXml = "<job name=\"build3\" />"; String md5 = goConfigFileDao.md5OfConfigFile(); ModelAndView mav = controller.postBuildAsXmlPartial("pipeline", "stage", 0, newXml, md5, response); assertThat(response.getStatus(), is(SC_OK)); assertThat(response.getContentType(), is(RESPONSE_CHARSET_JSON)); Json json = (Json) mav.getModel().get("json"); new JsonTester(json).shouldContain("{ 'result' : 'JobConfig changed successfully.' }"); }
From source file:com.thoughtworks.go.server.controller.GoConfigAdministrationControllerIntegrationTest.java
@Test public void shouldReturnXmlAndErrorMessageWhenPostOfPipelineAsInvalidXml() throws Exception { groupName = BasicPipelineConfigs.DEFAULT_GROUP; configHelper.addPipeline("pipeline", "stage", "build1", "build2"); String badXml = "<;askldjfa;dsklfja;sdjas;lkdf"; String md5 = goConfigFileDao.md5OfConfigFile(); ModelAndView mav = controller.postPipelineAsXmlPartial(0, groupName, badXml, md5, response); assertThat(response.getStatus(), is(SC_CONFLICT)); assertThat(response.getContentType(), is(RESPONSE_CHARSET_JSON)); Json json = (Json) mav.getModel().get("json"); new JsonTester(json).shouldContain( "{ 'result' : 'Error on line 1 of document : The markup in the document preceding the root element must be well-formed. Nested exception: The markup in the document preceding the root element must be well-formed.'," + " 'originalContent' : '" + badXml + "' }"); }
From source file:com.thoughtworks.go.server.controller.GoConfigAdministrationControllerIntegrationTest.java
@Test public void shouldReturnXmlAndErrorMessageWhenInvalidPostOfStageAsPartialXml() throws Exception { configHelper.addPipeline("pipeline", "stage", "build1", "build2"); String md5 = goConfigFileDao.md5OfConfigFile(); ModelAndView mav = controller.postStageAsXmlPartial("pipeline", 4, NEW_STAGE, md5, response); assertThat(response.getStatus(), is(SC_NOT_FOUND)); assertThat(response.getContentType(), is(RESPONSE_CHARSET_JSON)); Json json = (Json) mav.getModel().get("json"); JsonMap jsonMap = new JsonMap(); jsonMap.put("result", "Stage does not exist."); jsonMap.put("originalContent", NEW_STAGE); assertThat(json, is((Json) jsonMap)); }