Java Code Examples for org.springframework.web.servlet.ModelAndView#isReference()

The following examples show how to use org.springframework.web.servlet.ModelAndView#isReference() . 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: MvcViewRender.java    From onetwo with Apache License 2.0 6 votes vote down vote up
public void doRender(ModelAndView mv, HttpServletRequest request, HttpServletResponse response) throws Exception {
	if(localeResolver!=null){
		Locale locale = this.localeResolver.resolveLocale(request);
		response.setLocale(locale);
	}
	
	View view;
	if (mv.isReference()) {
		view = resolveViewName(mv.getViewName(), mv.getModel(), response.getLocale(), request);
		if (view == null) {
			throw new BaseException("Could not resolve view with name '" + mv.getViewName() + "' in '" + getClass().getSimpleName() + "'");
		}
	}
	else {
		view = mv.getView();
		if (view == null) {
			throw new BaseException("ModelAndView [" + mv + "] neither contains a view name nor a " + "View object in '" + getClass().getSimpleName() + "'");
		}
	}

	if (mv.getStatus() != null) {
		response.setStatus(mv.getStatus().value());
	}
	view.render(mv.getModel(), request, response);
}
 
Example 2
Source File: ModelAndViewMethodReturnValueHandler.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void handleReturnValue(@Nullable Object returnValue, MethodParameter returnType,
		ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {

	if (returnValue == null) {
		mavContainer.setRequestHandled(true);
		return;
	}

	ModelAndView mav = (ModelAndView) returnValue;
	if (mav.isReference()) {
		String viewName = mav.getViewName();
		mavContainer.setViewName(viewName);
		if (viewName != null && isRedirectViewName(viewName)) {
			mavContainer.setRedirectModelScenario(true);
		}
	}
	else {
		View view = mav.getView();
		mavContainer.setView(view);
		if (view instanceof SmartView && ((SmartView) view).isRedirectView()) {
			mavContainer.setRedirectModelScenario(true);
		}
	}
	mavContainer.setStatus(mav.getStatus());
	mavContainer.addAllAttributes(mav.getModel());
}
 
Example 3
Source File: ModelAndViewResolverMethodReturnValueHandler.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void handleReturnValue(@Nullable Object returnValue, MethodParameter returnType,
		ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {

	if (this.mavResolvers != null) {
		for (ModelAndViewResolver mavResolver : this.mavResolvers) {
			Class<?> handlerType = returnType.getContainingClass();
			Method method = returnType.getMethod();
			Assert.state(method != null, "No handler method");
			ExtendedModelMap model = (ExtendedModelMap) mavContainer.getModel();
			ModelAndView mav = mavResolver.resolveModelAndView(method, handlerType, returnValue, model, webRequest);
			if (mav != ModelAndViewResolver.UNRESOLVED) {
				mavContainer.addAllAttributes(mav.getModel());
				mavContainer.setViewName(mav.getViewName());
				if (!mav.isReference()) {
					mavContainer.setView(mav.getView());
				}
				return;
			}
		}
	}

	// No suitable ModelAndViewResolver...
	if (this.modelAttributeProcessor.supportsReturnType(returnType)) {
		this.modelAttributeProcessor.handleReturnValue(returnValue, returnType, mavContainer, webRequest);
	}
	else {
		throw new UnsupportedOperationException("Unexpected return type: " +
				returnType.getParameterType().getName() + " in method: " + returnType.getMethod());
	}
}
 
Example 4
Source File: ModelAndViewMethodReturnValueHandler.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void handleReturnValue(@Nullable Object returnValue, MethodParameter returnType,
		ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {

	if (returnValue == null) {
		mavContainer.setRequestHandled(true);
		return;
	}

	ModelAndView mav = (ModelAndView) returnValue;
	if (mav.isReference()) {
		String viewName = mav.getViewName();
		mavContainer.setViewName(viewName);
		if (viewName != null && isRedirectViewName(viewName)) {
			mavContainer.setRedirectModelScenario(true);
		}
	}
	else {
		View view = mav.getView();
		mavContainer.setView(view);
		if (view instanceof SmartView && ((SmartView) view).isRedirectView()) {
			mavContainer.setRedirectModelScenario(true);
		}
	}
	mavContainer.setStatus(mav.getStatus());
	mavContainer.addAllAttributes(mav.getModel());
}
 
Example 5
Source File: ModelAndViewResolverMethodReturnValueHandler.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void handleReturnValue(@Nullable Object returnValue, MethodParameter returnType,
		ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {

	if (this.mavResolvers != null) {
		for (ModelAndViewResolver mavResolver : this.mavResolvers) {
			Class<?> handlerType = returnType.getContainingClass();
			Method method = returnType.getMethod();
			Assert.state(method != null, "No handler method");
			ExtendedModelMap model = (ExtendedModelMap) mavContainer.getModel();
			ModelAndView mav = mavResolver.resolveModelAndView(method, handlerType, returnValue, model, webRequest);
			if (mav != ModelAndViewResolver.UNRESOLVED) {
				mavContainer.addAllAttributes(mav.getModel());
				mavContainer.setViewName(mav.getViewName());
				if (!mav.isReference()) {
					mavContainer.setView(mav.getView());
				}
				return;
			}
		}
	}

	// No suitable ModelAndViewResolver...
	if (this.modelAttributeProcessor.supportsReturnType(returnType)) {
		this.modelAttributeProcessor.handleReturnValue(returnValue, returnType, mavContainer, webRequest);
	}
	else {
		throw new UnsupportedOperationException("Unexpected return type: " +
				returnType.getParameterType().getName() + " in method: " + returnType.getMethod());
	}
}
 
Example 6
Source File: ModelAndViewMethodReturnValueHandler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void handleReturnValue(Object returnValue, MethodParameter returnType,
		ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {

	if (returnValue == null) {
		mavContainer.setRequestHandled(true);
		return;
	}

	ModelAndView mav = (ModelAndView) returnValue;
	if (mav.isReference()) {
		String viewName = mav.getViewName();
		mavContainer.setViewName(viewName);
		if (viewName != null && isRedirectViewName(viewName)) {
			mavContainer.setRedirectModelScenario(true);
		}
	}
	else {
		View view = mav.getView();
		mavContainer.setView(view);
		if (view instanceof SmartView) {
			if (((SmartView) view).isRedirectView()) {
				mavContainer.setRedirectModelScenario(true);
			}
		}
	}
	mavContainer.setStatus(mav.getStatus());
	mavContainer.addAllAttributes(mav.getModel());
}
 
Example 7
Source File: ModelAndViewResolverMethodReturnValueHandler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void handleReturnValue(Object returnValue, MethodParameter returnType,
		ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {

	if (this.mavResolvers != null) {
		for (ModelAndViewResolver mavResolver : this.mavResolvers) {
			Class<?> handlerType = returnType.getContainingClass();
			Method method = returnType.getMethod();
			ExtendedModelMap model = (ExtendedModelMap) mavContainer.getModel();
			ModelAndView mav = mavResolver.resolveModelAndView(method, handlerType, returnValue, model, webRequest);
			if (mav != ModelAndViewResolver.UNRESOLVED) {
				mavContainer.addAllAttributes(mav.getModel());
				mavContainer.setViewName(mav.getViewName());
				if (!mav.isReference()) {
					mavContainer.setView(mav.getView());
				}
				return;
			}
		}
	}

	// No suitable ModelAndViewResolver...
	if (this.modelAttributeProcessor.supportsReturnType(returnType)) {
		this.modelAttributeProcessor.handleReturnValue(returnValue, returnType, mavContainer, webRequest);
	}
	else {
		throw new UnsupportedOperationException("Unexpected return type: " +
				returnType.getParameterType().getName() + " in method: " + returnType.getMethod());
	}
}
 
Example 8
Source File: ModelAndViewMethodReturnValueHandler.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void handleReturnValue(Object returnValue, MethodParameter returnType,
		ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {

	if (returnValue == null) {
		mavContainer.setRequestHandled(true);
		return;
	}

	ModelAndView mav = (ModelAndView) returnValue;
	if (mav.isReference()) {
		String viewName = mav.getViewName();
		mavContainer.setViewName(viewName);
		if (viewName != null && isRedirectViewName(viewName)) {
			mavContainer.setRedirectModelScenario(true);
		}
	}
	else {
		View view = mav.getView();
		mavContainer.setView(view);
		if (view instanceof SmartView) {
			if (((SmartView) view).isRedirectView()) {
				mavContainer.setRedirectModelScenario(true);
			}
		}
	}
	mavContainer.addAllAttributes(mav.getModel());
}
 
Example 9
Source File: ModelAndViewResolverMethodReturnValueHandler.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void handleReturnValue(Object returnValue, MethodParameter returnType,
		ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {

	if (this.mavResolvers != null) {
		for (ModelAndViewResolver mavResolver : this.mavResolvers) {
			Class<?> handlerType = returnType.getContainingClass();
			Method method = returnType.getMethod();
			ExtendedModelMap model = (ExtendedModelMap) mavContainer.getModel();
			ModelAndView mav = mavResolver.resolveModelAndView(method, handlerType, returnValue, model, webRequest);
			if (mav != ModelAndViewResolver.UNRESOLVED) {
				mavContainer.addAllAttributes(mav.getModel());
				mavContainer.setViewName(mav.getViewName());
				if (!mav.isReference()) {
					mavContainer.setView(mav.getView());
				}
				return;
			}
		}
	}

	// No suitable ModelAndViewResolver...
	if (this.modelAttributeProcessor.supportsReturnType(returnType)) {
		this.modelAttributeProcessor.handleReturnValue(returnValue, returnType, mavContainer, webRequest);
	}
	else {
		throw new UnsupportedOperationException("Unexpected return type: " +
				returnType.getParameterType().getName() + " in method: " + returnType.getMethod());
	}
}