JasperReportsMultiFormatView (Spring Framework 3.2.1.RELEASE API)
Date: 2013-01-24

org.springframework.web.servlet.view.jasperreports

## Class JasperReportsMultiFormatView

- 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
          - - org.springframework.web.servlet.view.jasperreports.JasperReportsMultiFormatView

- All Implemented Interfaces:
    Aware, BeanNameAware, InitializingBean, ApplicationContextAware, ServletContextAware, View

      public class JasperReportsMultiFormatView
      extends AbstractJasperReportsView

  Jasper Reports view class that allows for the actual rendering format to be specified at runtime using a parameter contained in the model.

  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`:

       Map model = new HashMap();
       model.put("format", "pdf");

  Here `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` - `JasperReportsCsvView`
  - `html` - `JasperReportsHtmlView`
  - `pdf` - `JasperReportsPdfView`
  - `xls` - `JasperReportsXlsView`

  The format key can be changed using the `formatKey` property and the mapping key to view class mappings can be changed using the `formatMappings` property.

  Since:
    1.1.5
  Author:
    Rob Harrop, Juergen Hoeller
  See Also:
    `setFormatKey(java.lang.String)`, `setFormatMappings(java.util.Map<java.lang.String, java.lang.Class<? extends org.springframework.web.servlet.view.jasperreports.AbstractJasperReportsView>>)`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `DEFAULT_FORMAT_KEY` Default value used for format key: "format"

    - ### Fields inherited from class org.springframework.web.servlet.view.jasperreports.AbstractJasperReportsView

      `CONTENT_DISPOSITION_INLINE, HEADER_CONTENT_DISPOSITION`

    - ### Fields inherited from class org.springframework.web.servlet.view.AbstractView

      `DEFAULT_CONTENT_TYPE`

    - ### Fields inherited from class org.springframework.context.support.ApplicationObjectSupport

      `logger`

    - ### Fields inherited from interface org.springframework.web.servlet.View

      `PATH_VARIABLES, RESPONSE_STATUS_ATTRIBUTE, SELECTED_CONTENT_TYPE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `JasperReportsMultiFormatView()` Creates a new `JasperReportsMultiFormatView` instance with a default set of mappings.

  - ### Method Summary

    Methods
    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.

    - ### Methods inherited from class org.springframework.web.servlet.view.jasperreports.AbstractJasperReportsView

      `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`

    - ### Methods inherited from class org.springframework.web.servlet.view.AbstractUrlBasedView

      `afterPropertiesSet, checkResource, getUrl, setUrl, toString`

    - ### Methods inherited from class org.springframework.web.servlet.view.AbstractView

      `addStaticAttribute, createMergedOutputModel, createRequestContext, createTemporaryOutputStream, exposeModelAsRequestAttributes, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getStaticAttributes, isExposePathVariables, prepareResponse, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setExposePathVariables, setRequestContextAttribute, setResponseContentType, writeToResponse`

    - ### Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport

      `getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext`

    - ### 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

    - #### DEFAULT_FORMAT_KEY

          public static final String DEFAULT_FORMAT_KEY

      Default value used for format key: "format"
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### JasperReportsMultiFormatView

          public JasperReportsMultiFormatView()

      Creates a new `JasperReportsMultiFormatView` instance with a default set of mappings.

  - ### Method Detail

    - #### setFormatKey

          public void setFormatKey(String formatKey)

      Set the key of the model parameter that holds the format discriminator. Default is "format".

    - #### setFormatMappings

          public void setFormatMappings(Map<String,Class<? extends AbstractJasperReportsView>> formatMappings)

      Set the mappings of format discriminators to view class names. The default mappings are:

      - `csv` - `JasperReportsCsvView`
      - `html` - `JasperReportsHtmlView`
      - `pdf` - `JasperReportsPdfView`
      - `xls` - `JasperReportsXlsView`

    - #### setContentDispositionMappings

          public void setContentDispositionMappings(Properties mappings)

      Set the mappings of `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.

    - #### getContentDispositionMappings

          public Properties getContentDispositionMappings()

      Return the mappings of `Content-Disposition` header values to mapping keys. Mainly available for configuration through property paths that specify individual keys.

    - #### generatesDownloadContent

          protected boolean generatesDownloadContent()

      Description copied from class: `AbstractView`
      Return whether this view generates download content (typically binary content like PDF or Excel files).

      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.

      Overrides:
        `generatesDownloadContent` in class `AbstractView`
      See Also:
        `AbstractView.prepareResponse(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)`, `ServletResponse.getOutputStream()`

    - #### renderReport

          protected void renderReport(net.sf.jasperreports.engine.JasperPrint populatedReport,
                          Map<String,Object> model,
                          HttpServletResponse response)
                               throws Exception

      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. The rendering of the report is then delegated to an instance of that view class.
      Specified by:
        `renderReport` in class `AbstractJasperReportsView`
      Parameters:
        `populatedReport` - the populated `JasperPrint` to render
        `model` - the map containing report parameters
        `response` - the HTTP response the report should be rendered to
      Throws:
        `Exception` - if rendering failed
      See Also:
        `AbstractView.getContentType()`, `ServletResponse.setContentType(java.lang.String)`, `ServletResponse.setCharacterEncoding(java.lang.String)`