|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.context.support.ApplicationObjectSupport org.springframework.web.context.support.WebApplicationObjectSupport org.springframework.web.servlet.view.AbstractView org.springframework.web.servlet.view.AbstractUrlBasedView org.springframework.web.servlet.view.jasperreports.AbstractJasperReportsView
Base class for all JasperReports views. Applies on-the-fly compilation
of report designs as required and coordinates the rendering process.
The resource path of the main report needs to be specified as url
.
This class is responsible for getting report data from the model that has
been provided to the view. The default implementation checks for a model object
under the specified reportDataKey
first, then falls back to looking
for a value of type JRDataSource
, java.util.Collection
,
object array (in that order).
Provides support for sub-reports through the subReportUrls
and
subReportDataKeys
properties.
When using sub-reports, the master report should be configured using the
url
property and the sub-reports files should be configured using
the subReportUrls
property. Each entry in the subReportUrls
Map corresponds to an individual sub-report. The key of an entry must match up
to a sub-report parameter in your report file of type
net.sf.jasperreports.engine.JasperReport
,
and the value of an entry must be the URL for the sub-report file.
For sub-reports that require an instance of JRDataSource
, that is,
they don't have a hard-coded query for data retrieval, you can include the
appropriate data in your model as would with the data source for the parent report.
However, you must provide a List of parameter names that need to be converted to
JRDataSource
instances for the sub-report via the
subReportDataKeys
property. When using JRDataSource
instances for sub-reports, you must specify a value for the
reportDataKey
property, indicating the data to use for the main report.
Allows for exporter parameters to be configured declatively using the
exporterParameters
property. This is a Map
typed
property where the key of an entry corresponds to the fully-qualified name
of the static field for the JRExporterParameter
and the value
of an entry is the value you want to assign to the exporter parameter.
Response headers can be controlled via the headers
property. Spring
will attempt to set the correct value for the Content-Diposition
header
so that reports render correctly in Internet Explorer. However, you can override this
setting through the headers
property.
AbstractUrlBasedView.setUrl(java.lang.String)
,
getReportData(java.util.Map)
,
setSubReportDataKeys(String[])
,
setSubReportUrls(java.util.Properties)
,
setExporterParameters(java.util.Map)
,
setHeaders(java.util.Properties)
Field Summary | |
protected static String |
HEADER_CONTENT_DISPOSITION
Constant that defines "Content-Disposition" header. |
Fields inherited from class org.springframework.web.servlet.view.AbstractView |
DEFAULT_CONTENT_TYPE |
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport |
logger |
Constructor Summary | |
AbstractJasperReportsView()
|
Method Summary | |
protected net.sf.jasperreports.engine.JRDataSource |
convertReportData(Object value)
Convert the given report data value to a JRDataSource .
|
protected net.sf.jasperreports.engine.JRExporterParameter |
convertToExporterParameter(String fqFieldName)
Convert the given fully qualified field name to a corresponding JRExporterParameter instance. |
protected Map |
getExporterParameters()
Return the exporter parameters configured by the user. |
protected net.sf.jasperreports.engine.JasperReport |
getReport()
Allows sub-classes to get access to the JasperReport instance
loaded by Spring. |
protected net.sf.jasperreports.engine.design.JRCompiler |
getReportCompiler()
Return the JasperReports compiler to use for compiling a ".jrxml" file into a a report class. |
protected net.sf.jasperreports.engine.JRDataSource |
getReportData(Map model)
Find an instance of JRDataSource in the given model map or create an
appropriate JRDataSource for passed-in report data.
|
protected Class[] |
getReportDataTypes()
Return the value types that can be converted to a JRDataSource ,
in prioritized order. |
protected void |
initApplicationContext()
Checks to see that a valid report file URL is supplied in the configuration. |
protected void |
renderMergedOutputModel(Map model,
HttpServletRequest request,
HttpServletResponse response)
Finds the report data to use for rendering the report and then invokes the renderReport method that should be implemented by the subclass. |
protected abstract void |
renderReport(net.sf.jasperreports.engine.JasperReport report,
Map parameters,
net.sf.jasperreports.engine.JRDataSource dataSource,
HttpServletResponse response)
Subclasses should implement this method to perform the actual rendering process. |
void |
setExporterParameters(Map parameters)
Set the exporter parameters that should be used when rendering a view. |
void |
setHeaders(Properties headers)
Specify the set of headers that are included in each of response. |
void |
setReportDataKey(String reportDataKey)
Set the name of the model attribute that represents the report data. |
void |
setSubReportDataKeys(String[] subReportDataKeys)
Set the list of names corresponding to the model parameters that will contain data source objects for use in sub-reports. |
void |
setSubReportUrls(Properties subReports)
Specify resource paths which must be loaded as instances of JasperReport and passed to the JasperReports engine for
rendering as sub-reports, under the same keys as in this mapping. |
Methods inherited from class org.springframework.web.servlet.view.AbstractUrlBasedView |
getUrl, setUrl, toString |
Methods inherited from class org.springframework.web.servlet.view.AbstractView |
addStaticAttribute, createRequestContext, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getStaticAttributes, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setRequestContextAttribute |
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport |
getServletContext, getTempDir, getWebApplicationContext, isContextRequired |
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport |
getApplicationContext, getMessageSourceAccessor, requiredContextClass, setApplicationContext |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected static final String HEADER_CONTENT_DISPOSITION
Constructor Detail |
public AbstractJasperReportsView()
Method Detail |
public void setReportDataKey(String reportDataKey)
A JRDataSource
will be taken as-is. For other types, conversion
will apply: By default, a java.util.Collection
will be converted
to JRBeanCollectionDataSource
, and an object array to
JRBeanArrayDataSource
.
Note: If you pass in a Collection or object array in the model map for use as plain report parameter, rather than as report data to extract fields from, you need to specify the key for the actual report data to use, to avoid mis-detection of report data by type.
convertReportData(java.lang.Object)
,
JRDataSource
,
JRBeanCollectionDataSource
,
JRBeanArrayDataSource
public void setSubReportUrls(Properties subReports)
JasperReport
and passed to the JasperReports engine for
rendering as sub-reports, under the same keys as in this mapping.
subReports
- mapping between model keys and resource paths
(Spring resource locations)AbstractUrlBasedView.setUrl(java.lang.String)
,
ResourceLoader.getResource(java.lang.String)
public void setSubReportDataKeys(String[] subReportDataKeys)
JRDataSource
where applicable and will then
include the resulting JRDataSource
in the parameters passed into
the JasperReports engine.
The name specified in the list should correspond to an attribute in the
model Map, and to a sub-report data source parameter in your report file.
If you pass in JRDataSource
objects as model attributes,
specifing this list of keys is not required.
If you specify a list of sub-report data keys, it is required to also
specify a reportDataKey
for the main report, to avoid confusion
between the data source objects for the various reports involved.
subReportDataKeys
- list of names for sub-report data source objectssetReportDataKey(java.lang.String)
,
convertReportData(java.lang.Object)
,
JRDataSource
,
JRBeanCollectionDataSource
,
JRBeanArrayDataSource
public void setHeaders(Properties headers)
headers
- the headers to write to each response.public void setExporterParameters(Map parameters)
parameters
- Map
with the fully qualified field name of the
JRExporterParameter
instance as key
(e.g. "net.sf.jasperreports.engine.export.JRHtmlExporterParameter.IMAGES_URI")
and the value you wish to assign to the parameter as valueprotected Map getExporterParameters()
Map
containing the exporter parameters with instances
of JRExporterParameter
as the key.protected void initApplicationContext() throws ApplicationContextException
initApplicationContext
in class AbstractUrlBasedView
ApplicationContextException
protected net.sf.jasperreports.engine.JRExporterParameter convertToExporterParameter(String fqFieldName)
fqFieldName
- the fully qualified field name, consisting
of the class name followed by a dot followed by the field name
(e.g. "net.sf.jasperreports.engine.export.JRHtmlExporterParameter.IMAGES_URI")
protected net.sf.jasperreports.engine.design.JRCompiler getReportCompiler()
JRBshCompiler
,
which requires BeanShell on the class path.
JRCompiler
,
JRBshCompiler
protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception
renderReport
method that should be implemented by the subclass.
renderMergedOutputModel
in class AbstractView
model
- the model map, as passed in for view rendering. Must contain
a report data value that can be converted to a JRDataSource
,
acccording to the getReportData
method.request
- current HTTP requestresponse
- current HTTP response
Exception
- if rendering failedgetReportData(java.util.Map)
protected net.sf.jasperreports.engine.JRDataSource getReportData(Map model) throws IllegalArgumentException
JRDataSource
in the given model map or create an
appropriate JRDataSource for passed-in report data.
The default implementation checks for a model object under the
specified "reportDataKey" first, then falls back to looking for a value
of type JRDataSource
, java.util.Collection
,
object array (in that order).
model
- the model map, as passed in for view rendering
JRDataSource
IllegalArgumentException
- if no JRDataSource foundsetReportDataKey(java.lang.String)
,
convertReportData(java.lang.Object)
,
getReportDataTypes()
protected net.sf.jasperreports.engine.JRDataSource convertReportData(Object value) throws IllegalArgumentException
JRDataSource
.
The default implementation delegates to JasperReportUtils
unless
the report data value is an instance of JRDataSourceProvider
.
A JRDataSource
, JRDataSourceProvider
,
java.util.Collection
or object array is detected.
JRDataSource
s are returned as is, whilst JRDataSourceProvider
s
are used to create an instance of JRDataSource
which is then returned.
The latter two are converted to JRBeanCollectionDataSource
or
JRBeanArrayDataSource
, respectively.
value
- the report data value to convert
IllegalArgumentException
- if the value could not be convertedJasperReportsUtils.convertReportData(java.lang.Object)
,
JRDataSource
,
JRDataSourceProvider
,
JRBeanCollectionDataSource
,
JRBeanArrayDataSource
protected Class[] getReportDataTypes()
JRDataSource
,
in prioritized order. Should only return types that the
convertReportData
method is actually able to convert.
Default value types are: JRDataSource
,
JRDataSourceProvider
java.util.Collection
and Object
array.
convertReportData(java.lang.Object)
protected net.sf.jasperreports.engine.JasperReport getReport()
JasperReport
instance
loaded by Spring.
JasperReport
.protected abstract void renderReport(net.sf.jasperreports.engine.JasperReport report, Map parameters, net.sf.jasperreports.engine.JRDataSource dataSource, HttpServletResponse response) throws Exception
report
- the JasperReport
to renderparameters
- the map containing report parametersdataSource
- the JRDataSource
containing the report dataresponse
- the HTTP response the report should be rendered to
Exception
- if rendering failed
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |