Spring Framework ModelAndViewContainer - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework ModelAndViewContainer class.

This code example shows how to use the following methods:getModel, getView, setRedirectModel
 
	@Test 
	public void returnViewRedirect() throws Exception { 
		RedirectView redirectView = new RedirectView("testView"); 
		ModelMap redirectModel = new RedirectAttributesModelMap(); 
		this.mavContainer.setRedirectModel(redirectModel); 
		MethodParameter param = createReturnValueParam("view"); 
		this.handler.handleReturnValue(redirectView, param, this.mavContainer, this.webRequest); 
 
		assertSame(redirectView, this.mavContainer.getView()); 
		assertSame("Should have switched to the RedirectModel", redirectModel, this.mavContainer.getModel()); 
	} 
 
	private MethodParameter createReturnValueParam(String methodName) throws Exception { 
		Method method = getClass().getDeclaredMethod(methodName); 
		return new MethodParameter(method, -1); 
	} 
 
	View view() { 
		return null; 
8
CodeRank
This code example shows how to use the following methods:getModel, getViewName, setRedirectModel
	} 
 
	@Test 
	public void returnViewNameRedirect() throws Exception { 
		ModelMap redirectModel = new RedirectAttributesModelMap(); 
		this.mavContainer.setRedirectModel(redirectModel); 
		this.handler.handleReturnValue("redirect:testView", this.param, this.mavContainer, this.webRequest); 
		assertEquals("redirect:testView", this.mavContainer.getViewName()); 
		assertSame(redirectModel, this.mavContainer.getModel()); 
	} 
 
	@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()); 
	} 
8
CodeRank
This code example shows how to use the following methods:getModel, getView, setRedirectModel
	} 
 
	@Test 
	public void handleRedirectAttributesWithoutRedirect() throws Exception { 
		RedirectAttributesModelMap redirectAttributes  = new RedirectAttributesModelMap(); 
		mavContainer.setRedirectModel(redirectAttributes); 
 
		ModelAndView mav = new ModelAndView(); 
		handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest); 
 
		ModelMap model = mavContainer.getModel(); 
		assertEquals(null, mavContainer.getView()); 
		assertTrue(mavContainer.getModel().isEmpty()); 
		assertNotSame("RedirectAttributes should not be used if controller doesn't redirect", redirectAttributes, model); 
	} 
 
 
	private MethodParameter getReturnValueParam(String methodName) throws Exception { 
		Method method = getClass().getDeclaredMethod(methodName); 
		return new MethodParameter(method, -1); 
7
CodeRank
This code example shows how to use the following methods:addAttribute, getModel
		assertSame(mavContainer.getModel(), processor.resolveArgument(paramMap, mavContainer, webRequest, null)); 
	} 
 
	@Test 
	public void handleMapReturnValue() throws Exception { 
		mavContainer.addAttribute("attr1", "value1"); 
		Map<String, Object> returnValue = new ModelMap("attr2", "value2"); 
 
		processor.handleReturnValue(returnValue , returnParamMap, mavContainer, webRequest); 
 
		assertEquals("value1", mavContainer.getModel().get("attr1")); 
		assertEquals("value2", mavContainer.getModel().get("attr2")); 
	} 
 
	@SuppressWarnings("unused") 
	private Map<String, Object> map(Map<String, Object> map) { 
		return null; 
	} 
 
} 
7
CodeRank
This code example shows how to use the following methods:
	public void resolveArgument() throws Exception { 
		this.servletRequest.setContextPath("/myapp"); 
		this.servletRequest.setServletPath("/main"); 
		this.servletRequest.setPathInfo("/accounts"); 
 
		Object actual = this.resolver.resolveArgument(this.builderParam, new ModelAndViewContainer(), this.webRequest, null); 
 
		assertNotNull(actual); 
		assertEquals(ServletUriComponentsBuilder.class, actual.getClass()); 
		assertEquals("http://localhost/myapp/main", ((ServletUriComponentsBuilder) actual).build().toUriString()); 
	} 
 
 
	void handle(UriComponentsBuilder builder, ServletUriComponentsBuilder servletBuilder, int value) { 
	} 
 
} 
7
CodeRank
This code example shows how to use the following methods:getModel
 
	@Test 
	public void attributesAsNullValues() throws Exception { 
		this.request.addParameter("name", "Patty"); 
 
		this.mavContainer.getModel().put("testBean1", null); 
		this.mavContainer.getModel().put("testBean2", null); 
		this.mavContainer.getModel().put("testBean3", null); 
 
		assertNull(this.processor.resolveArgument( 
				this.testBeanModelAttr, this.mavContainer, this.webRequest, this.binderFactory)); 
 
		assertNull(this.processor.resolveArgument( 
				this.testBeanWithoutStringConstructorModelAttr, this.mavContainer, this.webRequest, this.binderFactory)); 
 
		Optional<TestBean> testBean = 
				(Optional<TestBean>) this.processor.resolveArgument( 
						this.testBeanWithOptionalModelAttr, this.mavContainer, this.webRequest, this.binderFactory); 
		assertFalse(testBean.isPresent()); 
	} 
 
7
CodeRank
This code example shows how to use the following methods:setRedirectModelScenario, setView
		if (returnValue == null) {
			return; 
		} 
		else if (returnValue instanceof View){
			View view = (View) returnValue;
			mavContainer.setView(view);
			if (view instanceof SmartView) {
				if (((SmartView) view).isRedirectView()) {
					mavContainer.setRedirectModelScenario(true);
				} 
			} 
		} 
		else { 
			// should not happen 
			throw new UnsupportedOperationException("Unexpected return type: " +
					returnType.getParameterType().getName() + " in method: " + returnType.getMethod());
		} 
	} 
 
} 
7
CodeRank
This code example shows how to use the following methods:isRequestHandled
	public void servletResponse() throws Exception { 
		MethodParameter servletResponseParameter = new MethodParameter(method, 0); 
 
		assertTrue("ServletResponse not supported", resolver.supportsParameter(servletResponseParameter)); 
 
		Object result = resolver.resolveArgument(servletResponseParameter, mavContainer, webRequest, null); 
		assertSame("Invalid result", servletResponse, result); 
		assertTrue(mavContainer.isRequestHandled()); 
	} 
 
	// SPR-8983 
 
	public void servletResponseNoMavContainer() throws Exception { 
		MethodParameter servletResponseParameter = new MethodParameter(method, 0); 
		assertTrue("ServletResponse not supported", resolver.supportsParameter(servletResponseParameter)); 
 
		Object result = resolver.resolveArgument(servletResponseParameter, null, webRequest, null); 
		assertSame("Invalid result", servletResponse, result); 
	} 
 
6
CodeRank
This code example shows how to use the following methods:
		resolver.resolveArgument(paramErrors, mavContainer, webRequest, null); 
	} 
 
	@Test(expected=IllegalStateException.class) 
	public void noBindingResult() throws Exception { 
		resolver.resolveArgument(paramErrors, new ModelAndViewContainer(), webRequest, null); 
	} 
 
	@SuppressWarnings("unused") 
	private void handle(Errors errors) { 
	} 
 
} 
7
CodeRank
This code example shows how to use the following methods:getModel
		assertTrue(processor.supportsReturnType(returnParamModel)); 
	} 
 
	@Test 
	public void resolveArgumentValue() throws Exception { 
		assertSame(mavContainer.getModel(), processor.resolveArgument(paramModel, mavContainer, webRequest, null)); 
	} 
 
	@Test 
	public void handleModelReturnValue() throws Exception { 
		mavContainer.addAttribute("attr1", "value1"); 
		Model returnValue = new ExtendedModelMap(); 
		returnValue.addAttribute("attr2", "value2"); 
 
		processor.handleReturnValue(returnValue , returnParamModel, mavContainer, webRequest); 
 
		assertEquals("value1", mavContainer.getModel().get("attr1")); 
		assertEquals("value2", mavContainer.getModel().get("attr2")); 
	} 
 
7
CodeRank
See Code Examples for Spring Framework ModelAndViewContainer Methods: