Java Code Examples for org.springframework.web.method.support.ModelAndViewContainer#setRedirectModel()
The following examples show how to use
org.springframework.web.method.support.ModelAndViewContainer#setRedirectModel() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModelFactoryTests.java From spring-analysis-note with MIT License | 6 votes |
@Test // SPR-12542 public void updateModelWhenRedirecting() throws Exception { String attributeName = "sessionAttr"; String attribute = "value"; ModelAndViewContainer container = new ModelAndViewContainer(); container.addAttribute(attributeName, attribute); String queryParam = "123"; String queryParamName = "q"; container.setRedirectModel(new ModelMap(queryParamName, queryParam)); container.setRedirectModelScenario(true); WebDataBinder dataBinder = new WebDataBinder(attribute, attributeName); WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class); given(binderFactory.createBinder(this.webRequest, attribute, attributeName)).willReturn(dataBinder); ModelFactory modelFactory = new ModelFactory(null, binderFactory, this.attributeHandler); modelFactory.updateModel(this.webRequest, container); assertEquals(queryParam, container.getModel().get(queryParamName)); assertEquals(1, container.getModel().size()); assertEquals(attribute, this.attributeStore.retrieveAttribute(this.webRequest, attributeName)); }
Example 2
Source File: ModelFactoryTests.java From java-technology-stack with MIT License | 6 votes |
@Test // SPR-12542 public void updateModelWhenRedirecting() throws Exception { String attributeName = "sessionAttr"; String attribute = "value"; ModelAndViewContainer container = new ModelAndViewContainer(); container.addAttribute(attributeName, attribute); String queryParam = "123"; String queryParamName = "q"; container.setRedirectModel(new ModelMap(queryParamName, queryParam)); container.setRedirectModelScenario(true); WebDataBinder dataBinder = new WebDataBinder(attribute, attributeName); WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class); given(binderFactory.createBinder(this.webRequest, attribute, attributeName)).willReturn(dataBinder); ModelFactory modelFactory = new ModelFactory(null, binderFactory, this.attributeHandler); modelFactory.updateModel(this.webRequest, container); assertEquals(queryParam, container.getModel().get(queryParamName)); assertEquals(1, container.getModel().size()); assertEquals(attribute, this.attributeStore.retrieveAttribute(this.webRequest, attributeName)); }
Example 3
Source File: ModelFactoryTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void updateModelWhenRedirecting() throws Exception { String attributeName = "sessionAttr"; String attribute = "value"; ModelAndViewContainer container = new ModelAndViewContainer(); container.addAttribute(attributeName, attribute); String queryParam = "123"; String queryParamName = "q"; container.setRedirectModel(new ModelMap(queryParamName, queryParam)); container.setRedirectModelScenario(true); WebDataBinder dataBinder = new WebDataBinder(attribute, attributeName); WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class); given(binderFactory.createBinder(this.webRequest, attribute, attributeName)).willReturn(dataBinder); ModelFactory modelFactory = new ModelFactory(null, binderFactory, this.sessionAttrsHandler); modelFactory.updateModel(this.webRequest, container); assertEquals(queryParam, container.getModel().get(queryParamName)); assertEquals(1, container.getModel().size()); assertEquals(attribute, this.sessionAttributeStore.retrieveAttribute(this.webRequest, attributeName)); }
Example 4
Source File: RedirectAttributesMethodArgumentResolver.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { DataBinder dataBinder = binderFactory.createBinder(webRequest, null, null); ModelMap redirectAttributes = new RedirectAttributesModelMap(dataBinder); mavContainer.setRedirectModel(redirectAttributes); return redirectAttributes; }