BIRT:指定 XML 数据源文件作为参数不起作用
使用 BIRT Designer 3.7.1,可以轻松地为 XML 文件数据源定义报告;但是,输入文件名最初会作为常量值写入 .rptdesign 文件中。一开始很好,但在现实生活中毫无用处。我想要的是通过 genReport.bat 脚本启动 BIRT ReportEngine,指定 XML 数据源文件的名称作为参数。这应该是微不足道的,但它出奇地困难...
我发现的是:您可以使用 params["datasource"].value,而不是将 XML 数据源文件定义为报告定义中的常量,这将是替换为运行时的参数值。此外,在 BIRT Designer 中,您可以定义报表参数(数据源)并为其指定默认值,例如“file://d:/sample.xml”。
然而,它不起作用。这是我在设计器中尝试预览的结果:
Cannot open the connection for the driver: org.eclipse.datatools.enablement.oda.xml.
org.eclipse.datatools.connectivity.oda.OdaException: The xml source file cannot be found or the URL is malformed.
ReportEngine,以 'genReport.bat -p "datasource=file://d:/sample.xml" xx.rptdesign' 开头,说得几乎相同。 当然,我已经确保 XML 文件存在,并尝试了文件 URL 的不同拼写。那么,出了什么问题呢?
Using BIRT designer 3.7.1, it's easy enough to define a report for an XML file data source; however, the input file name is written into the .rptdesign file as constant value, initially. Nice for the start, but useless in real life. What I want is start the BIRT ReportEngine via the genReport.bat script, specifying the name of the XML data source file as parameter. That should be trivial, but it is surprisingly difficult...
What I found out is this: Instead of defining the XML data source file as a constant in the report definition you can use params["datasource"].value, which will be replaced by the parameter value at runtime. Also, in BIRT Designer you can define the Report Parameter (datasource) and give it a default value, say "file://d:/sample.xml".
Yet, it doesn't work. This is the result of my Preview attempt in Designer:
Cannot open the connection for the driver: org.eclipse.datatools.enablement.oda.xml.
org.eclipse.datatools.connectivity.oda.OdaException: The xml source file cannot be found or the URL is malformed.
ReportEngine, started with 'genReport.bat -p "datasource=file://d:/sample.xml" xx.rptdesign' says nearly the same.
Of course, I have made sure that the XML file exists, and tried different spellings of the file URL. So, what's wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,它不会 - 至少,如果您将
&XML Data Source File
的值指定为params["datasource"].value
(而不是有效的值) XML 文件路径)在设计时,那么在尝试运行报表时您将收到错误。这是因为它尝试使用文字字符串params["datasource"].value
作为文件路径,而不是params["datasource" 的 value “].值
。相反,您需要使用事件处理程序脚本 - 具体来说,是
beforeOpen
脚本。为此,请执行以下操作:
beforeOpen
脚本。this.setExtensionProperty("FILELIST", params["datasource"].value);
如果您现在运行报表,您应该会发现参数
datasource
用于XML 文件位置。您可以在 BIRT 交换。
No, it won't - at least, if you specify the value of
&XML Data Source File
asparams["datasource"].value
(instead of a valid XML file path) at design time then you will get an error when attempting to run the report. This is because it is trying to use the literal stringparams["datasource"].value
for the file path, rather than the value ofparams["datasource"].value
.Instead, you need to use an event handler script - specifically, a
beforeOpen
script.To do this:
beforeOpen
script should be visible.this.setExtensionProperty("FILELIST", params["datasource"].value);
If you now run the report, you should find that the value of the parameter
datasource
is used for the XML file location.You can find out more about parameter-driven XML data sources on BIRT Exchange.
由于这是一个旧线程但仍然有用,我将添加一些信息:
添加一些脚本
Since this is an old thread but still usefull, i ll add some info :
add some script