org.springframework.web.servlet.view
Class InternalResourceView

java.lang.Object
  extended byorg.springframework.context.support.ApplicationObjectSupport
      extended byorg.springframework.web.context.support.WebApplicationObjectSupport
          extended byorg.springframework.web.servlet.view.AbstractView
              extended byorg.springframework.web.servlet.view.AbstractUrlBasedView
                  extended byorg.springframework.web.servlet.view.InternalResourceView
All Implemented Interfaces:
ApplicationContextAware, BeanNameAware, View
Direct Known Subclasses:
JstlView, TilesView

public class InternalResourceView
extends AbstractUrlBasedView

Wrapper for a JSP or other resource within the same web application. Exposes model objects as request attributes and forwards the request to the specified resource URL using a RequestDispatcher.

A URL for this view is supposed to specify a resource within the web application, suitable for RequestDispatcher's forward or include method.

If operating within an already included request or within a response that has already been committed, this view will fall back to an include instead of a forward. This can be enforced by calling response.flushBuffer() (which will commit the response) before rendering the view.

Author:
Rod Johnson, Juergen Hoeller
See Also:
RequestDispatcher.forward(javax.servlet.ServletRequest, javax.servlet.ServletResponse), RequestDispatcher.include(javax.servlet.ServletRequest, javax.servlet.ServletResponse), ServletResponse.flushBuffer()

Field Summary
 
Fields inherited from class org.springframework.web.servlet.view.AbstractView
DEFAULT_CONTENT_TYPE
 
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport
logger
 
Constructor Summary
InternalResourceView()
          Constructor for use as a bean.
InternalResourceView(String url)
          Create a new InternalResourceView with the given URL.
 
Method Summary
protected  void exposeHelpers(HttpServletRequest request)
          Expose helpers unique to each rendering operation.
protected  void exposeModelAsRequestAttributes(Map model, HttpServletRequest request)
          Expose the model objects in the given map as request attributes.
protected  String prepareForRendering(HttpServletRequest request, HttpServletResponse response)
          Prepare for rendering, and determine the request dispatcher path to forward to (or to include).
protected  void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response)
          Render the internal resource given the specified model.
protected  boolean useInclude(HttpServletRequest request, HttpServletResponse response)
          Determine whether to use RequestDispatcher's include or forward method.
 
Methods inherited from class org.springframework.web.servlet.view.AbstractUrlBasedView
getUrl, initApplicationContext, setUrl, toString
 
Methods inherited from class org.springframework.web.servlet.view.AbstractView
addStaticAttribute, createRequestContext, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getStaticAttributes, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setRequestContextAttribute
 
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, isContextRequired
 
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, requiredContextClass, setApplicationContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

InternalResourceView

public InternalResourceView()
Constructor for use as a bean.


InternalResourceView

public InternalResourceView(String url)
Create a new InternalResourceView with the given URL.

Parameters:
url - the URL to forward to
Method Detail

renderMergedOutputModel

protected void renderMergedOutputModel(Map model,
                                       HttpServletRequest request,
                                       HttpServletResponse response)
                                throws Exception
Render the internal resource given the specified model. This includes setting the model as request attributes.

Specified by:
renderMergedOutputModel in class AbstractView
Parameters:
model - combined output Map (never null), with dynamic values taking precedence over static attributes
request - current HTTP request
response - current HTTP response
Throws:
Exception - if rendering failed

exposeModelAsRequestAttributes

protected void exposeModelAsRequestAttributes(Map model,
                                              HttpServletRequest request)
                                       throws Exception
Expose the model objects in the given map as request attributes. Names will be taken from the model Map.

Called by renderMergedOutputModel. This method is suitable for all resources reachable by RequestDispatcher.

Parameters:
model - Map of model objects to expose
request - current HTTP request
Throws:
Exception
See Also:
renderMergedOutputModel(java.util.Map, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse), RequestDispatcher

exposeHelpers

protected void exposeHelpers(HttpServletRequest request)
                      throws Exception
Expose helpers unique to each rendering operation. This is necessary so that different rendering operations can't overwrite each other's contexts etc.

Called by renderMergedTemplateModel. The default implementation is empty. This method can be overridden to add custom helpers as request attributes.

Parameters:
request - current HTTP request
Throws:
Exception - if there's a fatal error while we're adding attributes
See Also:
renderMergedOutputModel(java.util.Map, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse), JstlView.exposeHelpers(javax.servlet.http.HttpServletRequest), TilesJstlView.exposeHelpers(javax.servlet.http.HttpServletRequest)

prepareForRendering

protected String prepareForRendering(HttpServletRequest request,
                                     HttpServletResponse response)
                              throws Exception
Prepare for rendering, and determine the request dispatcher path to forward to (or to include).

This implementation simply returns the configured URL. Subclasses can override this to determine a resource to render, typically interpreting the URL in a different manner.

Parameters:
request - current HTTP request
response - current HTTP response
Returns:
the request dispatcher path to use
Throws:
Exception - if preparations failed
See Also:
AbstractUrlBasedView.getUrl(), TilesView.prepareForRendering(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)

useInclude

protected boolean useInclude(HttpServletRequest request,
                             HttpServletResponse response)
Determine whether to use RequestDispatcher's include or forward method.

Performs a check whether an include URI attribute is found in the request, indicating an include request, and whether the response has already been committed. In both cases, an include will be performed, as a forward is not possible anymore.

Parameters:
request - current HTTP request
response - current HTTP response
Returns:
true for include, false for forward
See Also:
RequestDispatcher.forward(javax.servlet.ServletRequest, javax.servlet.ServletResponse), RequestDispatcher.include(javax.servlet.ServletRequest, javax.servlet.ServletResponse), ServletResponse.isCommitted(), UrlPathHelper.INCLUDE_URI_REQUEST_ATTRIBUTE


Copyright (C) 2003-2004 The Spring Framework Project.