public abstract class AbstractJasperReportsSingleFormatView extends AbstractJasperReportsView
AbstractJasperReportsView
to provide basic rendering logic
for views that use a fixed format, e.g. always PDF or always HTML.
Subclasses need to implement two template methods: createExporter
to create a JasperReports exporter for a specific output format, and
useWriter
to determine whether to write text or binary content.
This class is compatible with classic JasperReports releases back until 2.x.
As a consequence, it keeps using the JRExporter
API which got deprecated as of JasperReports 5.5.2 (early 2014).
createExporter()
,
useWriter()
CONTENT_DISPOSITION_INLINE, HEADER_CONTENT_DISPOSITION
DEFAULT_CONTENT_TYPE
logger
PATH_VARIABLES, RESPONSE_STATUS_ATTRIBUTE, SELECTED_CONTENT_TYPE
Constructor and Description |
---|
AbstractJasperReportsSingleFormatView() |
Modifier and Type | Method and Description |
---|---|
protected abstract net.sf.jasperreports.engine.JRExporter |
createExporter()
Create a JasperReports exporter for a specific output format,
which will be used to render the report to the HTTP response.
|
protected boolean |
generatesDownloadContent()
Return whether this view generates download content
(typically binary content like PDF or Excel files).
|
protected void |
renderReport(net.sf.jasperreports.engine.JasperPrint populatedReport,
java.util.Map<java.lang.String,java.lang.Object> model,
HttpServletResponse response)
Perform rendering for a single Jasper Reports exporter, that is,
for a pre-defined output format.
|
protected void |
renderReportUsingOutputStream(net.sf.jasperreports.engine.JRExporter exporter,
net.sf.jasperreports.engine.JasperPrint populatedReport,
HttpServletResponse response)
We need to write binary output to the response OutputStream.
|
protected void |
renderReportUsingWriter(net.sf.jasperreports.engine.JRExporter exporter,
net.sf.jasperreports.engine.JasperPrint populatedReport,
HttpServletResponse response)
We need to write text to the response Writer.
|
protected abstract boolean |
useWriter()
Return whether to use a
java.io.Writer to write text content
to the HTTP response. |
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, getRequestToExpose, getStaticAttributes, isExposePathVariables, prepareResponse, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setExposeContextBeansAsAttributes, setExposedContextBeanNames, setExposePathVariables, setRequestContextAttribute, setResponseContentType, writeToResponse
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
getApplicationContext, getMessageSourceAccessor, requiredContextClass, setApplicationContext
public AbstractJasperReportsSingleFormatView()
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, java.util.Map<java.lang.String,java.lang.Object> model, HttpServletResponse response) throws java.lang.Exception
renderReport
in class AbstractJasperReportsView
populatedReport
- the populated JasperPrint
to rendermodel
- the map containing report parametersresponse
- the HTTP response the report should be rendered tojava.lang.Exception
- if rendering failedAbstractView.getContentType()
,
ServletResponse.setContentType(java.lang.String)
,
ServletResponse.setCharacterEncoding(java.lang.String)
protected void renderReportUsingWriter(net.sf.jasperreports.engine.JRExporter exporter, net.sf.jasperreports.engine.JasperPrint populatedReport, HttpServletResponse response) throws java.lang.Exception
exporter
- the JasperReports exporter to usepopulatedReport
- the populated JasperPrint
to renderresponse
- the HTTP response the report should be rendered tojava.lang.Exception
- if rendering failedprotected void renderReportUsingOutputStream(net.sf.jasperreports.engine.JRExporter exporter, net.sf.jasperreports.engine.JasperPrint populatedReport, HttpServletResponse response) throws java.lang.Exception
exporter
- the JasperReports exporter to usepopulatedReport
- the populated JasperPrint
to renderresponse
- the HTTP response the report should be rendered tojava.lang.Exception
- if rendering failedprotected abstract net.sf.jasperreports.engine.JRExporter createExporter()
The useWriter
method determines whether the
output will be written as text or as binary content.
useWriter()
protected abstract boolean useWriter()
java.io.Writer
to write text content
to the HTTP response. Else, a java.io.OutputStream
will be used,
to write binary content to the response.