【发布时间】:2018-05-03 10:07:04
【问题描述】:
我在尝试基于脚本数据源生成 BIRT 报告时遇到此错误:
Caused by: org.mozilla.javascript.EcmaError: ReferenceError: "count" n'est pas défini (/report/data-sets/script-data-set[@id="248"]/method[@name="fetch"]#1)
英文:未定义变量“count”
我没有找到有关此案例的足够文档。
这些是 Java 类和报表模型。
感谢您的帮助。
AppDS(数据源类):
package projds;
import java.util.ArrayList;
import java.util.List;
public class AppDS {
public List<Entity> getEntities() {
List<Entity> t = new ArrayList<Entity>();
t.add(new Entity("A1"));
t.add(new Entity("A2"));
t.add(new Entity("A3"));
t.add(new Entity("A4"));
return t;
}
}
实体类:
package projds;
public class Entity {
String name;
public Entity() {
super();
}
public Entity(String name) {
super();
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
报告模型:
<?xml version="1.0" encoding="UTF-8"?>
<report xmlns="http://www.eclipse.org/birt/2005/design" version="3.2.23" id="1">
<property name="createdBy">Eclipse BIRT Designer Version 4.6.0.v201606072122</property>
<property name="units">in</property>
<property name="iconFile">/templates/first_report.gif</property>
<property name="bidiLayoutOrientation">ltr</property>
<property name="imageDPI">96</property>
<data-sources>
<script-data-source name="dsrc1" id="247"/>
</data-sources>
<data-sets>
<script-data-set name="dset1" id="248">
<list-property name="resultSetHints">
<structure>
<property name="position">0</property>
<property name="name">colName</property>
<property name="dataType">string</property>
</structure>
</list-property>
<list-property name="columnHints">
<structure>
<property name="columnName">colName</property>
<text-property name="displayName">The Name</text-property>
</structure>
</list-property>
<structure name="cachedMetaData">
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">colName</property>
<property name="dataType">string</property>
</structure>
</list-property>
</structure>
<property name="dataSource">dsrc1</property>
<method name="open"><![CDATA[importPackage(Packages.projds);
var dummyObject = new Object();
var gsh = new AppDS();
var data = gsh.getEntities();
var count = 0;]]></method>
<method name="fetch"><![CDATA[if(count < data.size()) {
row["colName"] = data.get(count).getName();
count++;
return true;
}
return false;]]></method>
<method name="close"><![CDATA[dummyObject = null;
gsh = null;
data = null;
var count = 0;]]></method>
</script-data-set>
</data-sets>
<styles>
<style name="report" id="110">
<property name="fontFamily">sans-serif</property>
<property name="fontSize">10pt</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>
<label id="245">
<property name="fontFamily">sans-serif</property>
<property name="fontSize">x-large</property>
<property name="fontWeight">bold</property>
<property name="textAlign">center</property>
<text-property name="text">Customer Listing</text-property>
</label>
<table id="325">
<property name="dataSet">dset1</property>
<list-property name="boundDataColumns">
<structure>
<property name="name">colName</property>
<text-property name="displayName">The Name</text-property>
<expression name="expression" type="javascript">dataSetRow["colName"]</expression>
<property name="dataType">string</property>
</structure>
</list-property>
<column id="334"/>
<header>
<row id="326">
<cell id="327">
<label id="328">
<text-property name="text">The Name</text-property>
</label>
</cell>
</row>
</header>
<detail>
<row id="329">
<cell id="330">
<data id="331">
<property name="resultSetColumn">colName</property>
</data>
</cell>
</row>
</detail>
<footer>
<row id="332">
<cell id="333"/>
</row>
</footer>
</table>
</body>
<property name="pageVariables">
<variable-element name="data">
<property name="type">report</property>
</variable-element>
</property>
</report>
【问题讨论】:
标签: dataset datasource birt