我在学习如何将 scriptlet 与iReport一起使用时遇到了麻烦。使用iReport中的预览,该 scriptlet 似乎可以正常构建和运行,该变量output
始终为null
.
heading
位于标题块中,文本框调用output
位于 detail1。
我注意到 println 没有出现在控制台中,但我想这不是 iReports 的工作方式。
public class ScriptletTestsScriptlet extends JRDefaultScriptlet {
public void beforeDetailEval() throws JRScriptletException {
System.out.println("Running Scriptlet");
String iGotMine = (String)this.getParameterValue("heading");
this.setVariableValue("output",": Hello World");
}
}
编辑:这是调用 jrxml
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="ScriptletTests" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" scriptletClass="com.marinecyb.hilit2.nbm.gui.export.ScriptletTestsScriptlet" uuid="199482dd-2d7f-495b-b6cc-5d96d4fe4bf7">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<scriptlet name="scriptlet1" class="com.marinecyb.hilit2.nbm.gui.export.ScriptletTestsScriptlet"/>
<parameter name="heading" class="java.lang.String">
<defaultValueExpression><![CDATA["Hello Computer"]]></defaultValueExpression>
</parameter>
<variable name="heading" class="java.lang.String"/>
<variable name="output" class="java.lang.String" calculation="System"/>
<pageHeader>
<band height="53">
<textField>
<reportElement uuid="cfd000be-6ed7-4da0-a9f6-6a9965073238" x="0" y="0" width="306" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$P{heading}]]></textFieldExpression>
</textField>
</band>
</pageHeader>
<detail>
<band height="125" splitType="Stretch">
<textField>
<reportElement uuid="9ed296b1-98ec-4960-97f5-c326ad57581c" x="35" y="44" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$V{output}]]></textFieldExpression>
</textField>
</band>
</detail>