Results 1 to 6 of 6

Thread: Spring 3 JasperReports exporter parameter changes

  1. #1
    Join Date
    Nov 2006
    Posts
    26

    Default Spring 3 JasperReports exporter parameter changes

    Hello all,

    I'm working on upgrading to Spring 3 and am running into a problem when passing exporter parameters as part of the model.

    We export all of our reports as Excel reports and use the postProcessReport hook to retrieve the sheet names and add it to the model but the mergeExporterParameters method has been removed.

    What is the new way to merge exporter parameters from the model into the exporter?

    Thanks,
    Dustin

  2. #2
    Join Date
    Nov 2006
    Posts
    26

    Default

    For anyone else interested,

    I'm currently getting around this with the below code.

    Code:
        /**
         * Perform rendering for a single Jasper Reports exporter, that is,
         * for a pre-defined output format.
         */
        @Override
        protected void renderReport(final JasperPrint populatedReport, final Map model, final HttpServletResponse response) throws Exception {
            JRExporter exporter = createExporter();
            Map mergedExporterParameters = getConvertedExporterParameters();
            //return old behavior of merging model attributes
            mergedExporterParameters = mergeExporterParameters(model, mergedExporterParameters);
            //end old behavior of merging model attributes
            if(!CollectionUtils.isEmpty(mergedExporterParameters)) {
                exporter.setParameters(mergedExporterParameters);
            }
            if(useWriter()) {
                renderReportUsingWriter(exporter, populatedReport, response);
            } else {
                renderReportUsingOutputStream(exporter, populatedReport, response);
            }
        }
    Dustin

  3. #3
    Join Date
    Mar 2010
    Posts
    2

    Default

    Hi Dustin,

    I am running into the same problem. I am using Spring 3.0 and Jasperreports 3.5.2. However, the mergeExporterParameters is not a method that exists in Spring 3.0 (AbstractJasperReportsSingleFormatView.html)

    http://static.springsource.org/sprin...ormatView.html

    I was wanting to know how you were able to get around the margins issue in Excel..More Specifically, Could you post the code for MergeExportedParameters method that you are using if you don't mind..

    Thanks much,
    Sri

  4. #4
    Join Date
    Nov 2006
    Posts
    26

    Default

    Hi Sri,

    I think it's mostly just a copy/paste of Spring code but here it is

    Code:
        /**
         * Merges the configured JRExporterParameters with any specified in the supplied model data.
         * JRExporterParameters in the model override those specified in the configuration.
         * @see #setExporterParameters(java.util.Map)
         */
        private Map mergeExporterParameters(Map model, Map convertedExporterParameters) {
            Map mergedParameters = new HashMap();
            if(!CollectionUtils.isEmpty(convertedExporterParameters)) {
                mergedParameters.putAll(convertedExporterParameters);
            }
            for(Iterator it = model.keySet().iterator(); it.hasNext();) {
                Object key = it.next();
                if(key instanceof JRExporterParameter) {
                    Object value = model.get(key);
                    if(value instanceof String || value instanceof String[]) {
                        mergedParameters.put(key, value);
                    } else {
                        if(logger.isWarnEnabled()) {
                            logger.warn("Ignoring exporter parameter [" + key + "]: value is not a String or String[]");
                        }
                    }
                }
            }
            return mergedParameters;
        }
    To handle specific Excel issues we modified the view classes slightly to get them to write to files instead of the servlet output stream so we can re-open the result file and tweak it with Apache POI.

    Thanks,
    Dustin

  5. #5
    Join Date
    Mar 2010
    Posts
    2

    Default

    Thanks Dustin..

  6. #6
    Join Date
    Dec 2010
    Posts
    315

    Default

    If you're not using Spring's built-in Jasper views, it might be more easier to use DynamicJasper. It's similar to the way you're doing it.

    I advise you read the tutorials I've written for integrating Spring MVC 3 and Jasper. I've also provided a downloadable Maven build. The tutorials are very detailed. In addition, the application itself is well-commented.

    http://krams915.blogspot.com/p/tutorials.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •