Package net.solarnetwork.web.support
Class SimpleCsvView
java.lang.Object
org.springframework.context.support.ApplicationObjectSupport
org.springframework.web.context.support.WebApplicationObjectSupport
org.springframework.web.servlet.view.AbstractView
net.solarnetwork.web.support.AbstractView
net.solarnetwork.web.support.SimpleCsvView
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanNameAware,org.springframework.context.ApplicationContextAware,org.springframework.web.context.ServletContextAware,org.springframework.web.servlet.View
Spring
View for turning objects into
CSV through JavaBean introspection.
The character encoding of the output must be specified in the
AbstractView.setContentType(String) (e.g. text/csv;charset=UTF-8).
The configurable properties of this class are:
- dataModelKey
- If not null, then use this model key as the data object to
render as CSV. Otherwise, export just the first available key's associated
object. Defaults to
DEFAULT_DATA_MODEL_KEY. - fieldOrderKey
- If not null, then use this model key as an ordered Collection
of exported field names, such that the CSV columns will be exported in the
specified order. If not specified, then for Map objects the output order will
be determined by the natural iteration order of the Map keys, and for
JavaBean objects the bean properties will be exported in case-insensitive
alphabetical order. Defaults to
DEFAULT_FIELD_ORDER_KEY.
- Version:
- 1.1
- Author:
- matt
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault content type.static final StringThe default value for thedataModelKeyproperty.static final StringThe default value for thefieldOrderKeyproperty.Fields inherited from class net.solarnetwork.web.support.AbstractView
DEFAULT_JAVA_BEAN_IGNORE_PROPERTIES, DEFAULT_JAVA_BEAN_STRING_VALUESFields inherited from class org.springframework.web.servlet.view.AbstractView
DEFAULT_CONTENT_TYPEFields inherited from class org.springframework.context.support.ApplicationObjectSupport
loggerFields inherited from interface org.springframework.web.servlet.View
PATH_VARIABLES, RESPONSE_STATUS_ATTRIBUTE, SELECTED_CONTENT_TYPE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGet the data model key.Get the field order key.protected voidrenderMergedOutputModel(Map<String, Object> model, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) voidsetDataModelKey(String dataModelKey) Set the data model key.voidsetFieldOrderKey(String fieldOrderKey) Set the field order key.Methods inherited from class net.solarnetwork.web.support.AbstractView
getJavaBeanIgnoreProperties, getJavaBeanTreatAsStringValues, getModelObjectIgnoreTypes, getPropertySerializerRegistrar, getResponseCharacterEncoding, render, setJavaBeanIgnoreProperties, setJavaBeanTreatAsStringValues, setModelObjectIgnoreTypes, setPropertySerializerRegistrarMethods inherited from class org.springframework.web.servlet.view.AbstractView
addStaticAttribute, createMergedOutputModel, createRequestContext, createTemporaryOutputStream, exposeModelAsRequestAttributes, generatesDownloadContent, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getRequestToExpose, getStaticAttributes, isExposePathVariables, prepareResponse, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setExposeContextBeansAsAttributes, setExposedContextBeanNames, setExposePathVariables, setRequestContextAttribute, setResponseContentType, toString, writeToResponseMethods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContextMethods inherited from class org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, initApplicationContext, requiredContextClass, setApplicationContext
-
Field Details
-
DEFAULT_CSV_CONTENT_TYPE
Default content type.- See Also:
-
DEFAULT_DATA_MODEL_KEY
The default value for thedataModelKeyproperty.- See Also:
-
DEFAULT_FIELD_ORDER_KEY
The default value for thefieldOrderKeyproperty.- See Also:
-
-
Constructor Details
-
SimpleCsvView
public SimpleCsvView()Default constructor.
-
-
Method Details
-
renderMergedOutputModel
protected void renderMergedOutputModel(Map<String, Object> model, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws Exception- Specified by:
renderMergedOutputModelin classorg.springframework.web.servlet.view.AbstractView- Throws:
Exception
-
getDataModelKey
Get the data model key.- Returns:
- the key to set
-
setDataModelKey
Set the data model key.- Parameters:
dataModelKey- the key to set
-
getFieldOrderKey
Get the field order key.- Returns:
- the key to set
-
setFieldOrderKey
Set the field order key.- Parameters:
fieldOrderKey- the key to set
-