Class MarshallingView

  extended by
      extended by
          extended by org.springframework.web.servlet.view.AbstractView
              extended by org.springframework.web.servlet.view.xml.MarshallingView
All Implemented Interfaces:
BeanNameAware, ApplicationContextAware, ServletContextAware, View

public class MarshallingView
extends AbstractView

Spring-MVC View that allows for response context to be rendered as the result of marshalling by a Marshaller.

The Object to be marshalled is supplied as a parameter in the model and then detected during response rendering. Users can either specify a specific entry in the model via the sourceKey property or have Spring locate the Source object.

Arjen Poutsma

Field Summary
static java.lang.String DEFAULT_CONTENT_TYPE
          Default content type.
Fields inherited from class
Constructor Summary
          Constructs a new MarshallingView with no Marshaller set.
MarshallingView(Marshaller marshaller)
          Constructs a new MarshallingView with the given Marshaller set.
Method Summary
protected  void initApplicationContext()
          Subclasses can override this for custom initialization behavior.
protected  java.lang.Object locateToBeMarshalled(java.util.Map model)
          Locates the object to be marshalled.
protected  void renderMergedOutputModel(java.util.Map model, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Subclasses must implement this method to actually render the view.
 void setMarshaller(Marshaller marshaller)
          Sets the Marshaller to be used by this view.
 void setModelKey(java.lang.String modelKey)
          Set the name of the model key that represents the object to be marshalled.
Methods inherited from class org.springframework.web.servlet.view.AbstractView
addStaticAttribute, createRequestContext, createTemporaryOutputStream, exposeModelAsRequestAttributes, generatesDownloadContent, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getStaticAttributes, prepareResponse, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setRequestContextAttribute, toString, writeToResponse
Methods inherited from class
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
Methods inherited from class
getApplicationContext, getMessageSourceAccessor, requiredContextClass, setApplicationContext
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Field Detail


public static final java.lang.String DEFAULT_CONTENT_TYPE
Default content type. Overridable as bean property.

See Also:
Constant Field Values
Constructor Detail


public MarshallingView()
Constructs a new MarshallingView with no Marshaller set. The marshaller must be set after construction by invoking setMarshaller(Marshaller).


public MarshallingView(Marshaller marshaller)
Constructs a new MarshallingView with the given Marshaller set.

Method Detail


public void setMarshaller(Marshaller marshaller)
Sets the Marshaller to be used by this view.


public void setModelKey(java.lang.String modelKey)
Set the name of the model key that represents the object to be marshalled. If not specified, the model map will be searched for a supported value type.

See Also:


protected void initApplicationContext()
                               throws BeansException
Description copied from class: ApplicationObjectSupport
Subclasses can override this for custom initialization behavior.

The default implementation is empty. Called by ApplicationObjectSupport.initApplicationContext(org.springframework.context.ApplicationContext).

initApplicationContext in class ApplicationObjectSupport
ApplicationContextException - in case of initialization errors
BeansException - if thrown by ApplicationContext methods
See Also:


protected void renderMergedOutputModel(java.util.Map model,
                                       javax.servlet.http.HttpServletRequest request,
                                       javax.servlet.http.HttpServletResponse response)
                                throws java.lang.Exception
Description copied from class: AbstractView
Subclasses must implement this method to actually render the view.

The first step will be preparing the request: In the JSP case, this would mean setting model objects as request attributes. The second step will be the actual rendering of the view, for example including the JSP via a RequestDispatcher.

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


protected java.lang.Object locateToBeMarshalled(java.util.Map model)
                                         throws javax.servlet.ServletException
Locates the object to be marshalled. The default implementation first attempts to look under the configured model key, if any, before attempting to locate an object of supported type.

model - the model Map
the Object to be marshalled (or null if none found)
javax.servlet.ServletException - if the model object specified by the model key is not supported by the marshaller
See Also: