BIRT:指定 XML 数据源文件作为参数不起作用

发布于 2025-01-02 18:24:52 字数 752 浏览 3 评论 0原文

使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

世俗缘 2025-01-09 18:24:52

我发现:您可以使用 params["datasource"].value,而不是在报表定义中将 XML 数据源文件定义为常量,该值将在运行时被参数值替换。

不,它不会 - 至少,如果您将 &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 交换

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.

No, it won't - at least, if you specify the value of &XML Data Source File as params["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 string params["datasource"].value for the file path, rather than the value of params["datasource"].value.

Instead, you need to use an event handler script - specifically, a beforeOpen script.

To do this:

  • Left-click on your data source in the Data Explorer.
  • In the main Report Design pane, click on the Script tab (instead of the Layout tab). A blank beforeOpen script should be visible.
  • Copy and paste the following code into the script:

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.

勿忘初心 2025-01-09 18:24:52

由于这是一个旧线程但仍然有用,我将添加一些信息:

  • 在编辑数据源中,添加一些 url 以包含示例数据来创建数据集
  • 创建数据集
  • 然后删除 url,如图所示

在此处输入图像描述

添加一些脚本

在此处输入图像描述

Since this is an old thread but still usefull, i ll add some info :

  • In the edit datasource, add some url to have sample data to create your dataset
  • Create your dataset
  • Then remove url as shown

enter image description here

add some script

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文