【问题标题】:Jasper API prints only first report other reports are printed as blankJasper API 仅打印第一个报告,其他报告打印为空白
【发布时间】:2019-05-23 18:20:58
【问题描述】:

我们正在使用 jasper API (JasperFillManager.fillReport,JasperExportManager.exportReportToPdfFile)

我们想用不同的参数在循环中执行那个报告,所以添加了以下代码

    JasperPrint jasperPrint = null;
            // Fill report
            Iterator i1 = l1.iterator();
            Iterator i2 = l2.iterator();
            int i = 1;
            while (i1.hasNext() && i2.hasNext()) {
                parameters.put("SUBJECTOID", (String) i1.next());
                parameters.put("HISTORYRECORD", (String) i2.next());
                try (ProfilePoint fillReport = ProfilePoint
                        .profileAction("ProfAction_ReportHelper_fillJasperReport")) {
                    jasperReport = JasperCompileManager.compileReport(jrxmlPath);

                    jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, emptyDataSource);
                    System.out.println("fillReport**********" + i);

                }

                // Export to PDF
                try (ProfilePoint exportReport = ProfilePoint
                        .profileAction("ProfAction_ReportHelper_exportJasperReport")) {
                    JasperExportManager.exportReportToPdfFile(jasperPrint,
                            "C:\\JASPER\\JASPEROUTPUT\\Report" + i + ".pdf");
                    System.out.println("exportReportToPdfFile**********" + i);
                }
                i++;
                jasperPrint = null;
                jasperReport = null;

那么我们有 15 个参数会发生什么,因此生成了 15 个 PDF 文件,但只有第一个 PDF 文件包含数据,其他 14 个是空白的。

我们尝试了多种方法,例如编译一次,多次编译,将jasper代码提取到方法中,但结果仍然相同

jasper 或类似的东西中是否有任何缓存或某种设置?

【问题讨论】:

  • 1) 看起来您正在传递空数据源 JasperFillManager.fillReport(jasperReport, parameters, emptyDataSource); 2) 您的参数可能有问题 parameters.put("SUBJECTOID", (String) i1.next()); 3) 您没有发布完整的简单示例 - 很难帮助您。也许 jrxml 是错误的; 4) Is there any cache or some kind of setting in jasper or similar something? - 没有缓存。您是否在每次迭代时检查 jasperPrint 对象?
  • 我们传递的是空数据源,因为在 jrxml 本身中我们传递的数据集如下code new net.sf.jasperreports.engine.data.JRXmlDataSource("http://i4515-vm2.ptcnet.ptc.com/Windchill/servlet/XML4Cognos?proc=com_ptc_windchill_enterprise_report_ReportTask%23QMS-CustomerExperience&SUBJECT_OID=OR%3acom.ptc.qualitymanagement.cem.CustomerExperience%3a"+$P{SUBJECTOID}+"&HISTORY_RECORD_OID=OR%3acom.ptc.windchill.history.HistoryRecord%3a"+$P{HISTORYRECORD}+"&uid=demo&locale=en-us&jasper=true","/dataset/data/row")
  • 所以空数据源应该不是问题,我们在 jasper 中创建了两个参数,我们在数据集 url 中插入了相同的参数,我们添加了记录器语句,并确定参数正在正确传递,但它的非常令人惊讶的是,该循环仅适用于第一次迭代,从下一次迭代开始它只打印空 PDF 文件,jrxml 相当大。
  • 您是在每次迭代中创建一个新的空数据源实例,还是为所有迭代使用一个实例?后者不起作用,因为数据源实例在报告生成期间被消耗,您需要每次使用新实例,或者至少使用 moveFirst() 倒回数据源。
  • 感谢您的回复...数据源您的意思是传递参数JREmptyDataSource emptyDataSource 对吗?我只通过了该数据源一次,我是否需要每次都创建新的?它的空数据源为什么重要?

标签: java jasper-reports


【解决方案1】:

谢谢@dada67 建议它有效

我为每次迭代都传递了新的空数据源并且它有效。

非常感谢..!!!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多