简体   繁体   English

使用XML数据源生成动态BIRT报告时出现问题

[英]Issue in generating Dynamic BIRT reports using XML data source

We are using BIRT 3.7 api to generate dynamic PDF. 我们正在使用BIRT 3.7 API生成动态PDF。 We are setting up XML data source using below logic. 我们正在使用以下逻辑来设置XML数据源。 In below snippet we provides XML string as data source. 在下面的代码段中,我们提供XML字符串作为数据源。 Strangely, since last week dynamic data is not getting populated from xml. 奇怪的是,由于上周没有从xml中填充动态数据。 It is not throwing any exception as such even in the FINEST log level. 即使在FINEST日志级别,它也不会引发任何异常。 As we have not updated any jars so not able to figure out the changes which made this functionality to break. 由于我们尚未更新任何jar,因此无法找出导致此功能中断的更改。 PDF are getting generated without dynamic values. PDF生成时没有动态值。

Is there something else I can try out to set xml data source in java to birt template. 还有什么我可以尝试将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();

Where are you setting your report parameters to the task? 您在哪里为任务设置报告参数? If you refer to that values as dynamic values that's what you need: 如果您将这些值称为动态值 ,那么您需要的是:

task.setParameterValue("param_name", value);

Just follow this model . 只要遵循这种模式 Otherwise you'll obviously get a blank report, as no parameters are specified. 否则,您显然会得到一个空白报告,因为未指定任何参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM