public class JasperReportsMultiFormatView extends AbstractJasperReportsView
This view works on the concept of a format key and a mapping key.
The format key is used to pass the mapping key from your Controller
to Spring through as part of the model and the mapping key is used to map
a logical format to an actual JasperReports view class.
For example, you might add the following code to your Controller
:
MapHeremodel = new HashMap (); model.put("format", "pdf");
format
is the format key and pdf
is the mapping key.
When rendering a report, this class looks for a model parameter under the
format key, which by default is format
. It then uses the value of
this parameter to lookup the actual View
class to use.
The default mappings for the format lookup are:
csv
- JasperReportsCsvView
html
- JasperReportsHtmlView
pdf
- JasperReportsPdfView
xls
- JasperReportsXlsView
The format key can be changed using the formatKey
property.
The applicable key-to-view-class mappings can be configured using the
formatMappings
property.
setFormatKey(java.lang.String)
,
setFormatMappings(java.util.Map<java.lang.String, java.lang.Class<? extends org.springframework.web.servlet.view.jasperreports.AbstractJasperReportsView>>)
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_FORMAT_KEY
Default value used for format key: "format"
|
CONTENT_DISPOSITION_INLINE, HEADER_CONTENT_DISPOSITION
DEFAULT_CONTENT_TYPE
logger
PATH_VARIABLES, RESPONSE_STATUS_ATTRIBUTE, SELECTED_CONTENT_TYPE
Constructor and Description |
---|
JasperReportsMultiFormatView()
Creates a new
JasperReportsMultiFormatView instance
with a default set of mappings. |
Modifier and Type | Method and Description |
---|---|
protected boolean |
generatesDownloadContent()
Return whether this view generates download content
(typically binary content like PDF or Excel files).
|
Properties |
getContentDispositionMappings()
Return the mappings of
Content-Disposition header values to
mapping keys. |
protected void |
renderReport(net.sf.jasperreports.engine.JasperPrint populatedReport,
Map<String,Object> model,
HttpServletResponse response)
Locates the format key in the model using the configured discriminator key and uses this
key to lookup the appropriate view class from the mappings.
|
void |
setContentDispositionMappings(Properties mappings)
Set the mappings of
Content-Disposition header values to
mapping keys. |
void |
setFormatKey(String formatKey)
Set the key of the model parameter that holds the format discriminator.
|
void |
setFormatMappings(Map<String,Class<? extends AbstractJasperReportsView>> formatMappings)
Set the mappings of format discriminators to view class names.
|
convertExporterParameters, convertParameterValue, convertReportData, convertToExporterParameter, createReport, exposeLocalizationContext, fillReport, getConvertedExporterParameters, getExporterParameter, getExporterParameters, getJdbcDataSource, getReport, getReportData, getReportDataTypes, initApplicationContext, isUrlRequired, loadReport, loadReport, onInit, postProcessReport, renderMergedOutputModel, setConvertedExporterParameters, setExporterParameters, setHeaders, setJdbcDataSource, setReportDataKey, setSubReportDataKeys, setSubReportUrls
afterPropertiesSet, checkResource, getUrl, setUrl, toString
addStaticAttribute, createMergedOutputModel, createRequestContext, createTemporaryOutputStream, exposeModelAsRequestAttributes, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getStaticAttributes, isExposePathVariables, prepareResponse, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setExposePathVariables, setRequestContextAttribute, setResponseContentType, writeToResponse
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
getApplicationContext, getMessageSourceAccessor, requiredContextClass, setApplicationContext
public static final String DEFAULT_FORMAT_KEY
public JasperReportsMultiFormatView()
JasperReportsMultiFormatView
instance
with a default set of mappings.public void setFormatKey(String formatKey)
public void setFormatMappings(Map<String,Class<? extends AbstractJasperReportsView>> formatMappings)
csv
- JasperReportsCsvView
html
- JasperReportsHtmlView
pdf
- JasperReportsPdfView
xls
- JasperReportsXlsView
public void setContentDispositionMappings(Properties mappings)
Content-Disposition
header values to
mapping keys. If specified, Spring will look at these mappings to determine
the value of the Content-Disposition
header for a given
format mapping.public Properties getContentDispositionMappings()
Content-Disposition
header values to
mapping keys. Mainly available for configuration through property paths
that specify individual keys.protected boolean generatesDownloadContent()
AbstractView
The default implementation returns false
. Subclasses are
encouraged to return true
here if they know that they are
generating download content that requires temporary caching on the
client side, typically via the response OutputStream.
protected void renderReport(net.sf.jasperreports.engine.JasperPrint populatedReport, Map<String,Object> model, HttpServletResponse response) throws Exception
renderReport
in class AbstractJasperReportsView
populatedReport
- the populated JasperPrint
to rendermodel
- the map containing report parametersresponse
- the HTTP response the report should be rendered toException
- if rendering failedAbstractView.getContentType()
,
ServletResponse.setContentType(java.lang.String)
,
ServletResponse.setCharacterEncoding(java.lang.String)