BIRT,如何获取报告参数的长度?
我一直在尝试制作一个启用多项选择的列表框报告参数。我正在尝试根据此参数过滤我的报告。我写了一段类似这样的代码,但它不起作用;
importPackage(Packages.java.util.logging);
var fileHandler = new FileHandler("/tmp/birt.log", true);
var rootLogger = Logger.getLogger("");
rootLogger.addHandler(fileHandler);
var queryString = "";
queryString = "select * from public.r_"+params["rid"]+"_0 where (r_date_1 >= '"+params["startdate"]+"' and r_date_2 <'"+params["enddate"]+"')";
queryString += " and (r_vchar_3=";
filterIPLength = reportContext.getParameterValue("filterIP").length;
Logger.getAnonymousLogger().info("Parameter Count: "+filterIPLength);
for(i = 0; i<filterIPLength; i++) {
queryString += "'"+reportContext.getParameterValue("filterIP")[i]+"'";
if (i != filterIPLength - 1) {
queryString += "or r_vchar_3=";
}
}
queryString += ")";
this.queryText = queryString;
这里的问题是,reportContext.getParameterValue("filterIP").length;
行始终返回 1,即使我选择了多个参数,并且报告仅显示第一个选定的数据,因为 for 循环仅运行一次。
什么可能导致这个问题?我该如何调试和解决它?
任何想法将不胜感激。
I have been trying to make a list box report parameter with multiple choice enabled. I'm trying to filter my report based on this parameter. I have wrote a code something like this, but it is not working;
importPackage(Packages.java.util.logging);
var fileHandler = new FileHandler("/tmp/birt.log", true);
var rootLogger = Logger.getLogger("");
rootLogger.addHandler(fileHandler);
var queryString = "";
queryString = "select * from public.r_"+params["rid"]+"_0 where (r_date_1 >= '"+params["startdate"]+"' and r_date_2 <'"+params["enddate"]+"')";
queryString += " and (r_vchar_3=";
filterIPLength = reportContext.getParameterValue("filterIP").length;
Logger.getAnonymousLogger().info("Parameter Count: "+filterIPLength);
for(i = 0; i<filterIPLength; i++) {
queryString += "'"+reportContext.getParameterValue("filterIP")[i]+"'";
if (i != filterIPLength - 1) {
queryString += "or r_vchar_3=";
}
}
queryString += ")";
this.queryText = queryString;
the problem here is, reportContext.getParameterValue("filterIP").length;
line always returns 1, even though I choose multiple parameters and the report only shows the first selected data since for loop runs only once.
What may cause this problem? How can i debug and solve it?
Any ideas will be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的脚本应该可以工作,至少它可以在我的 BIRT 版本(2.6、Eclipse 3.6、Win-32)中工作。我写了一个小的简约报告(有效)来追踪问题,可能它可以帮助您调试。
:
Eclipse BIRT Designer 版本 2.6.1.v20100902 构建 <2.6.1.v20100915-1750> <属性名称=“单位”>在
<结构>
<报告 xmlns="http://www.eclipse.org/birt/2005/design" version="3.2.22" id="1">
<属性名称=“iconFile”>/templates/blank_report.gif
<属性名称=“bidiLayoutOrientation”>ltr
<属性名称=“imageDPI”>120
<参数>
<标量参数名称=“NewParameter”id=“7”>
<属性名称=“valueType”>静态
<属性名称=“数据类型”>字符串
<属性名称=“不同”>true
<列表属性名称=“选择列表”>
<结构>
<属性名称=“值”>123
<属性名称=“标签”>测试
<结构>
<属性名称=“值”>124
<属性名称=“标签”>test2
<属性名称=“paramType”>多值
<属性名称=“controlType”>列表框
<属性名称=“必须匹配”>true
<属性名称=“fixedOrder”>true
<结构名称=“格式”>
<属性名称=“类别”>未格式化
<数据源>
<方法名称=“beforeOpen”>
<数据集>
<属性名称=“位置”>0
<属性名称=“名称”>测试
<属性名称=“数据类型”>字符串
<列表属性名称=“columnHints”>
<结构>
<属性名称=“列名称”>测试
<结构名称=“cachedMetaData”>
<列表属性名称=“结果集”>
<结构>
<属性名称=“位置”>1
<属性名称=“名称”>测试
<属性名称=“数据类型”>字符串
<属性名称=“dataSource”>数据源
<样式>
Your script should work, at least it works in my BIRT version (2.6, Eclipse 3.6, Win-32). I've written a small minimalistic report (which works) to track down the problem, probably it can help you debugging.:
<?xml version="1.0" encoding="UTF-8"?>
<report xmlns="http://www.eclipse.org/birt/2005/design" version="3.2.22" id="1">
<property name="createdBy">Eclipse BIRT Designer Version 2.6.1.v20100902 Build <2.6.1.v20100915-1750></property>
<property name="units">in</property>
<property name="iconFile">/templates/blank_report.gif</property>
<property name="bidiLayoutOrientation">ltr</property>
<property name="imageDPI">120</property>
<parameters>
<scalar-parameter name="NewParameter" id="7">
<property name="valueType">static</property>
<property name="dataType">string</property>
<property name="distinct">true</property>
<list-property name="selectionList">
<structure>
<property name="value">123</property>
<property name="label">test</property>
</structure>
<structure>
<property name="value">124</property>
<property name="label">test2</property>
</structure>
</list-property>
<property name="paramType">multi-value</property>
<property name="controlType">list-box</property>
<property name="mustMatch">true</property>
<property name="fixedOrder">true</property>
<structure name="format">
<property name="category">Unformatted</property>
</structure>
</scalar-parameter>
</parameters>
<data-sources>
<script-data-source name="Data Source" id="95">
<method name="beforeOpen"><![CDATA[paramLength = reportContext.getParameterValue("NewParameter").length;]]></method>
</script-data-source>
</data-sources>
<data-sets>
<script-data-set name="Data Set" id="96">
<list-property name="resultSetHints">
<structure>
<property name="position">0</property>
<property name="name">test</property>
<property name="dataType">string</property>
</structure>
</list-property>
<list-property name="columnHints">
<structure>
<property name="columnName">test</property>
</structure>
</list-property>
<structure name="cachedMetaData">
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">test</property>
<property name="dataType">string</property>
</structure>
</list-property>
</structure>
<property name="dataSource">Data Source</property>
</script-data-set>
</data-sets>
<styles>
<style name="report" id="4">
<property name="fontFamily">sans-serif</property>
<property name="fontSize">10pt</property>
</style>
<style name="crosstab-cell" id="5">
<property name="borderBottomColor">#CCCCCC</property>
<property name="borderBottomStyle">solid</property>
<property name="borderBottomWidth">1pt</property>
<property name="borderLeftColor">#CCCCCC</property>
<property name="borderLeftStyle">solid</property>
<property name="borderLeftWidth">1pt</property>
<property name="borderRightColor">#CCCCCC</property>
<property name="borderRightStyle">solid</property>
<property name="borderRightWidth">1pt</property>
<property name="borderTopColor">#CCCCCC</property>
<property name="borderTopStyle">solid</property>
<property name="borderTopWidth">1pt</property>
</style>
<style name="crosstab" id="6">
<property name="borderBottomColor">#CCCCCC</property>
<property name="borderBottomStyle">solid</property>
<property name="borderBottomWidth">1pt</property>
<property name="borderLeftColor">#CCCCCC</property>
<property name="borderLeftStyle">solid</property>
<property name="borderLeftWidth">1pt</property>
<property name="borderRightColor">#CCCCCC</property>
<property name="borderRightStyle">solid</property>
<property name="borderRightWidth">1pt</property>
<property name="borderTopColor">#CCCCCC</property>
<property name="borderTopStyle">solid</property>
<property name="borderTopWidth">1pt</property>
</style>
</styles>
<page-setup>
<simple-master-page name="Simple MasterPage" id="2">
<page-footer>
<text id="3">
<property name="contentType">html</property>
<text-property name="content"><![CDATA[<value-of>new Date()</value-of>]]></text-property>
</text>
</page-footer>
</simple-master-page>
</page-setup>
<body>
<data id="107">
<property name="whiteSpace">nowrap</property>
<property name="dataSet">Data Set</property>
<list-property name="boundDataColumns">
<structure>
<property name="name">test</property>
<text-property name="displayName">test</text-property>
<expression name="expression" type="javascript">dataSetRow["test"]</expression>
<property name="dataType">string</property>
</structure>
</list-property>
<property name="resultSetColumn">test</property>
</data>
<text-data id="93">
<expression name="valueExpr">"Param length is " + paramLength</expression>
<property name="contentType">html</property>
</text-data>
</body>
</report>