我一直在尝试创建一个启用了多项选择的列表框报告参数。我正在尝试根据此参数过滤我的报告。我写了类似这样的代码,但它没有用;
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循环只运行一次。
可能导致此问题的原因是什么?我该如何调试和解决它?
任何想法将不胜感激。
答案 0 :(得分:2)
你的脚本应该可以工作,至少它适用于我的BIRT版本(2.6,Eclipse 3.6,Win-32)。我写了一个小的简约报告(可以工作)来追踪问题,可能它可以帮助你调试。:
<?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>