Search in sources :

Example 6 with ModelMap

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;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RedirectAttributes(org.springframework.web.servlet.mvc.support.RedirectAttributes) ModelMap(org.springframework.ui.ModelMap) ModelAndView(org.springframework.web.servlet.ModelAndView)

Example 7 with ModelMap

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"));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) ModelMap(org.springframework.ui.ModelMap) ModelAndView(org.springframework.web.servlet.ModelAndView) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Test(org.junit.Test)

Example 8 with ModelMap

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"));
}
Also used : ModelMap(org.springframework.ui.ModelMap) ModelAndView(org.springframework.web.servlet.ModelAndView) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Test(org.junit.Test)

Example 9 with ModelMap

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);
}
Also used : RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) ModelMap(org.springframework.ui.ModelMap) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) Test(org.junit.Test)

Example 10 with ModelMap

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());
}
Also used : RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) ModelMap(org.springframework.ui.ModelMap) RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) Test(org.junit.Test)

Aggregations

ModelMap (org.springframework.ui.ModelMap)48 Test (org.junit.Test)23 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)18 ModelAndView (org.springframework.web.servlet.ModelAndView)11 RedirectAttributesModelMap (org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap)9 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)5 Map (java.util.Map)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 IOException (java.io.IOException)3 Date (java.util.Date)3 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)3 HttpSessionRequiredException (org.springframework.web.HttpSessionRequiredException)3 RedirectAttributes (org.springframework.web.servlet.mvc.support.RedirectAttributes)3 NimbusClient (backtype.storm.utils.NimbusClient)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 HttpSession (javax.servlet.http.HttpSession)2