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 this
lookup are:
csv - JasperReportsCsvViewhtml - JasperReportsHtmlViewpdf - JasperReportsPdfViewxls - JasperReportsXlsViewThe format key can be changed using the formatKey
property and the mapping key to view class mappings can be changed 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_DISPOSITIONDEFAULT_CONTENT_TYPEPATH_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, setSubReportUrlsafterPropertiesSet, checkResource, getUrl, setUrl, toStringaddStaticAttribute, createMergedOutputModel, createRequestContext, createTemporaryOutputStream, exposeModelAsRequestAttributes, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getStaticAttributes, isExposePathVariables, prepareResponse, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setExposePathVariables, setRequestContextAttribute, setResponseContentType, writeToResponsegetServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContextpublic 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 - JasperReportsCsvViewhtml - JasperReportsHtmlViewpdf - JasperReportsPdfViewxls - JasperReportsXlsViewpublic 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()
AbstractViewThe 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 AbstractJasperReportsViewpopulatedReport - 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)