Class MarshallingView
- All Implemented Interfaces:
- Aware,- BeanNameAware,- ApplicationContextAware,- ServletContextAware,- View
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.
- Since:
- 3.0
- Author:
- Arjen Poutsma, Juergen Hoeller
- 
Field SummaryFieldsFields inherited from class org.springframework.context.support.ApplicationObjectSupportloggerFields inherited from interface org.springframework.web.servlet.ViewPATH_VARIABLES, RESPONSE_STATUS_ATTRIBUTE, SELECTED_CONTENT_TYPE
- 
Constructor SummaryConstructorsConstructorDescriptionConstruct a newMarshallingViewwith noMarshallerset.MarshallingView(Marshaller marshaller) Constructs a newMarshallingViewwith the givenMarshallerset.
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidSubclasses can override this for custom initialization behavior.protected booleanisEligibleForMarshalling(String modelKey, Object value) Check whether the given value from the current view's model is eligible for marshalling through the configuredMarshaller.protected ObjectlocateToBeMarshalled(Map<String, Object> model) Locate the object to be marshalled.protected voidrenderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) Subclasses must implement this method to actually render the view.voidsetMarshaller(Marshaller marshaller) Set theMarshallerto be used by this view.voidsetModelKey(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.AbstractViewaddStaticAttribute, createMergedOutputModel, createRequestContext, createTemporaryOutputStream, exposeModelAsRequestAttributes, formatViewName, generatesDownloadContent, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getRequestToExpose, getStaticAttributes, isExposePathVariables, prepareResponse, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setExposeContextBeansAsAttributes, setExposedContextBeanNames, setExposePathVariables, setRequestContextAttribute, setResponseContentType, toString, writeToResponseMethods inherited from class org.springframework.web.context.support.WebApplicationObjectSupportgetServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContextMethods inherited from class org.springframework.context.support.ApplicationObjectSupportgetApplicationContext, getMessageSourceAccessor, obtainApplicationContext, requiredContextClass, setApplicationContext
- 
Field Details- 
DEFAULT_CONTENT_TYPEDefault content type. Overridable as bean property.- See Also:
 
 
- 
- 
Constructor Details- 
MarshallingViewpublic MarshallingView()Construct a newMarshallingViewwith noMarshallerset. The marshaller must be set after construction by invokingsetMarshaller(org.springframework.oxm.Marshaller).
- 
MarshallingViewConstructs a newMarshallingViewwith the givenMarshallerset.
 
- 
- 
Method Details- 
setMarshallerSet theMarshallerto be used by this view.
- 
setModelKeySet 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:
 
- 
initApplicationContextprotected void initApplicationContext()Description copied from class:ApplicationObjectSupportSubclasses can override this for custom initialization behavior.The default implementation is empty. Called by ApplicationObjectSupport.initApplicationContext(ApplicationContext).
- 
renderMergedOutputModelprotected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws ExceptionDescription copied from class:AbstractViewSubclasses 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:
- renderMergedOutputModelin 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
 
- 
locateToBeMarshalled@Nullable protected Object locateToBeMarshalled(Map<String, Object> model) throws IllegalStateExceptionLocate 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. - Parameters:
- model- the model Map
- Returns:
- the Object to be marshalled (or nullif none found)
- Throws:
- IllegalStateException- if the model object specified by the model key is not supported by the marshaller
- See Also:
 
- 
isEligibleForMarshallingCheck whether the given value from the current view's model is eligible for marshalling through the configuredMarshaller.The default implementation calls Marshaller.supports(Class), unwrapping a givenJAXBElementfirst if applicable.- Parameters:
- modelKey- the value's key in the model (never- null)
- value- the value to check (never- null)
- Returns:
- whether the given value is to be considered as eligible
- See Also:
 
 
-