* @param request current portlet render request
* @param response current portlet render response
* @throws Exception if there's a problem rendering the view
*/
protected void render(ModelAndView mv, RenderRequest request, RenderResponse response) throws Exception {
View view = null;
if (mv.isReference()) {
// We need to resolve the view name.
view = resolveViewName(mv.getViewName(), mv.getModelInternal(), request);
if (view == null) {
throw new PortletException("Could not resolve view with name '" + mv.getViewName() +
"' in portlet with name '" + getPortletName() + "'");
}
}
else {
// No need to lookup: the ModelAndView object contains the actual View object.
Object viewObject = mv.getView();
if (viewObject == null) {
throw new PortletException("ModelAndView [" + mv + "] neither contains a view name nor a " +
"View object in portlet with name '" + getPortletName() + "'");
}
if (!(viewObject instanceof View)) {
throw new PortletException(
"View object [" + viewObject + "] is not an instance of [org.springframework.web.servlet.View] - " +
"DispatcherPortlet does not support any other view types");
}
view = (View) viewObject;
}
if (view == null) {
throw new PortletException("Could not resolve view with name '" + mv.getViewName() +
"' in portlet with name '" + getPortletName() + "'");
}
// Set the content type on the response if needed and if possible.
// The Portlet spec requires the content type to be set on the RenderResponse;
// it's not sufficient to let the View set it on the ServletResponse.
if (response.getContentType() != null) {
if (logger.isDebugEnabled()) {
logger.debug("Portlet response content type already set to [" + response.getContentType() + "]");
}
}
else {
// No Portlet content type specified yet -> use the view-determined type.
String contentType = view.getContentType();
if (contentType != null) {
if (logger.isDebugEnabled()) {
logger.debug("Setting portlet response content type to view-determined type [" + contentType + "]");
}
response.setContentType(contentType);