use of org.springframework.ui.ModelMap in project spring-framework by spring-projects.
the class RequestMappingHandlerAdapter method getModelAndView.
private ModelAndView getModelAndView(ModelAndViewContainer mavContainer, ModelFactory modelFactory, NativeWebRequest webRequest) throws Exception {
modelFactory.updateModel(webRequest, mavContainer);
if (mavContainer.isRequestHandled()) {
return null;
}
ModelMap model = mavContainer.getModel();
ModelAndView mav = new ModelAndView(mavContainer.getViewName(), model, mavContainer.getStatus());
if (!mavContainer.isViewReference()) {
mav.setView((View) mavContainer.getView());
}
if (model instanceof RedirectAttributes) {
Map<String, ?> flashAttributes = ((RedirectAttributes) model).getFlashAttributes();
HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class);
RequestContextUtils.getOutputFlashMap(request).putAll(flashAttributes);
}
return mav;
}
use of org.springframework.ui.ModelMap in project spring-framework by spring-projects.
the class UrlFilenameViewControllerTests method withFlashAttributes.
@Test
public void withFlashAttributes() throws Exception {
UrlFilenameViewController ctrl = new UrlFilenameViewController();
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/index");
request.setAttribute(DispatcherServlet.INPUT_FLASH_MAP_ATTRIBUTE, new ModelMap("name", "value"));
MockHttpServletResponse response = new MockHttpServletResponse();
ModelAndView mv = ctrl.handleRequest(request, response);
assertEquals("index", mv.getViewName());
assertEquals(1, mv.getModel().size());
assertEquals("value", mv.getModel().get("name"));
}
use of org.springframework.ui.ModelMap in project spring-framework by spring-projects.
the class ParameterizableViewControllerTests method handleRequestWithFlashAttributes.
@Test
public void handleRequestWithFlashAttributes() throws Exception {
this.request.setAttribute(DispatcherServlet.INPUT_FLASH_MAP_ATTRIBUTE, new ModelMap("name", "value"));
ModelAndView mav = this.controller.handleRequest(this.request, new MockHttpServletResponse());
assertEquals(1, mav.getModel().size());
assertEquals("value", mav.getModel().get("name"));
}
use of org.springframework.ui.ModelMap in project spring-framework by spring-projects.
the class ModelAndViewMethodReturnValueHandlerTests method handleRedirectAttributesWithCustomPrefix.
@Test
public void handleRedirectAttributesWithCustomPrefix() throws Exception {
RedirectAttributesModelMap redirectAttributes = new RedirectAttributesModelMap();
mavContainer.setRedirectModel(redirectAttributes);
ModelAndView mav = new ModelAndView("myRedirect:viewName", "attrName", "attrValue");
handler.setRedirectPatterns("myRedirect:*");
handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest);
ModelMap model = mavContainer.getModel();
assertEquals("myRedirect:viewName", mavContainer.getViewName());
assertEquals("attrValue", model.get("attrName"));
assertSame(redirectAttributes, model);
}
use of org.springframework.ui.ModelMap in project spring-framework by spring-projects.
the class ViewNameMethodReturnValueHandlerTests method returnViewCustomRedirect.
@Test
public void returnViewCustomRedirect() throws Exception {
ModelMap redirectModel = new RedirectAttributesModelMap();
this.mavContainer.setRedirectModel(redirectModel);
this.handler.setRedirectPatterns("myRedirect:*");
this.handler.handleReturnValue("myRedirect:testView", this.param, this.mavContainer, this.webRequest);
assertEquals("myRedirect:testView", this.mavContainer.getViewName());
assertSame(redirectModel, this.mavContainer.getModel());
}
Aggregations