【问题标题】:Issue in generating Dynamic BIRT reports using XML data source使用 XML 数据源生成动态 BIRT 报告的问题
【发布时间】:2013-07-10 17:32:07
【问题描述】:

我们正在使用 BIRT 3.7 api 来生成动态 PDF。我们正在设置 XML 数据源 使用以下逻辑。在下面的 sn-p 中,我们提供 XML 字符串作为数据源。 奇怪的是,自上周以来,动态数据并没有从 xml 中填充。即使在 FINEST 日志级别,它也不会抛出任何异常。 由于我们尚未更新任何 jar,因此无法找出导致此功能中断的更改。生成的 PDF 没有动态值。

还有什么我可以尝试将java中的xml数据源设置为birt模板。

String paramStr = readFileAsString(servletContext.getRealPath("/WEB-INF/classes")
+ "/resources/test.xml");

FileInputStream fis = new FileInputStream(servletContext.getRealPath("/WEB-INF/classes")
+ "/resources/BirtXmlDataTest.rptdesign");
IReportRunnable design = birtReportEngine.openReportDesign(fis);
DesignElementHandle designElementHandle = design.getDesignHandle();
ModuleHandle moduleHandle = designElementHandle.getModuleHandle();
ElementFactory designElementFactory = designElementHandle.getElementFactory();
OdaDataSourceHandle dataSourceHandle = designElementFactory.newOdaDataSource("Data Source",
"org.eclipse.birt.report.data.oda.xml");

moduleHandle.getDataSources().add(dataSourceHandle);

IRunAndRenderTask task = birtReportEngine
.createRunAndRenderTask(design);
PDFRenderOption options = new PDFRenderOption();
options.setSupportedImageFormats("JPG;PNG;BMP;SVG");
options.setOutputFormat(PDFRenderOption.OUTPUT_FORMAT_PDF);
options.setEmitterID(PDFRenderOption.OUTPUT_EMITTERID_PDF);
// options.setOutputStream(response.getOutputStream());
File file = new File("d:\\test" + File.separator + "file2.pdf");
FileOutputStream fos = new FileOutputStream(file);
// options.setOutputStream(response.getOutputStream());
options.setOutputStream(fos);

HashMap<String, Object> contextMap = new HashMap<String, Object>();
contextMap.put("org.eclipse.birt.report.data.oda.xml.inputStream",
new ByteArrayInputStream(paramStr.getBytes()));
contextMap.put(
"org.eclipse.birt.report.data.oda.xml.closeInputStream",
Boolean.TRUE);
task.setAppContext(contextMap);
task.setRenderOption(options);
task.run();
task.close();

【问题讨论】:

    标签: birt xmldatasource


    【解决方案1】:

    您在哪里为任务设置报告参数?如果您将该值称为 动态值,那么这就是您所需要的:

    task.setParameterValue("param_name", value);
    

    只需关注this model。否则你显然会得到一个空白报告,因为没有指定参数。

    【讨论】:

    • XML 输入流是在字符串“paramStr”中实际读取的,它被放入上下文映射中,如下所示。 contextMap.put("org.eclipse.birt.report.data.oda.xml.inputStream", new ByteArrayInputStream(paramStr.getBytes())); contextMap.put("org.eclipse.birt.report.data.oda.xml.closeInputStream", Boolean.TRUE); task.setAppContext(contextMap);一周前它实际上运行良好。
    • 因此,如果没有对代码进行更改,问题可能出在 xml 文件中。您是否已完成调试并重新检查是否加载了正确的文件?
    猜你喜欢
    • 1970-01-01
    • 2012-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-12
    相关资源
    最近更新 更多