public class MarshallingView extends AbstractView
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.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_CONTENT_TYPE
Default content type.
|
logger
PATH_VARIABLES, RESPONSE_STATUS_ATTRIBUTE, SELECTED_CONTENT_TYPE
Constructor and Description |
---|
MarshallingView()
Construct a new
MarshallingView with no Marshaller set. |
MarshallingView(Marshaller marshaller)
Constructs a new
MarshallingView with the given Marshaller set. |
Modifier and Type | Method and Description |
---|---|
protected void |
initApplicationContext()
Subclasses can override this for custom initialization behavior.
|
protected boolean |
isEligibleForMarshalling(java.lang.String modelKey,
java.lang.Object value)
Check whether the given value from the current view's model is eligible
for marshalling through the configured
Marshaller . |
protected java.lang.Object |
locateToBeMarshalled(java.util.Map<java.lang.String,java.lang.Object> model)
Locate the object to be marshalled.
|
protected void |
renderMergedOutputModel(java.util.Map<java.lang.String,java.lang.Object> model,
HttpServletRequest request,
HttpServletResponse response)
Subclasses must implement this method to actually render the view.
|
void |
setMarshaller(Marshaller marshaller)
Set 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.
|
addStaticAttribute, 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, writeToResponse
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
getApplicationContext, getMessageSourceAccessor, obtainApplicationContext, requiredContextClass, setApplicationContext
public static final java.lang.String DEFAULT_CONTENT_TYPE
public MarshallingView()
MarshallingView
with no Marshaller
set.
The marshaller must be set after construction by invoking setMarshaller(org.springframework.oxm.Marshaller)
.public MarshallingView(Marshaller marshaller)
MarshallingView
with the given Marshaller
set.public void setMarshaller(Marshaller marshaller)
Marshaller
to be used by this view.public void setModelKey(java.lang.String modelKey)
Marshaller.supports(Class)
protected void initApplicationContext()
ApplicationObjectSupport
The default implementation is empty. Called by
ApplicationObjectSupport.initApplicationContext(org.springframework.context.ApplicationContext)
.
protected void renderMergedOutputModel(java.util.Map<java.lang.String,java.lang.Object> model, HttpServletRequest request, HttpServletResponse response) throws java.lang.Exception
AbstractView
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.
renderMergedOutputModel
in class AbstractView
model
- combined output Map (never null
),
with dynamic values taking precedence over static attributesrequest
- current HTTP requestresponse
- current HTTP responsejava.lang.Exception
- if rendering failed@Nullable protected java.lang.Object locateToBeMarshalled(java.util.Map<java.lang.String,java.lang.Object> model) throws java.lang.IllegalStateException
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 Mapnull
if none found)java.lang.IllegalStateException
- if the model object specified by the
model key is not supported by the marshallersetModelKey(String)
protected boolean isEligibleForMarshalling(java.lang.String modelKey, java.lang.Object value)
Marshaller
.
The default implementation calls Marshaller.supports(Class)
,
unwrapping a given JAXBElement
first if applicable.
modelKey
- the value's key in the model (never null
)value
- the value to check (never null
)Marshaller.supports(Class)