JasperReport 型の EGL レポート・ハンドラーは、JasperReports エンジンが実行時にアクセスできるコード・ブロックを提供します。 事前定義関数名により、これらのコード・ブロックの一部が、 JasperReports によるレポートの埋め込みの際に発生するイベントに結合されます。 このようなイベントには、ページ、行項目、またはレポート自体の先頭または末尾が含まれることがあります。その他のカスタム関数を直接 XML 設計ファイル・ソースから呼び出すことができます。
「新規 EGL レポート・ハンドラー」ウィザードは、 レポート埋め込みイベントに対応する関数名のリストを提供します。 例えば、JasperReports は、ページを入力する前に「beforePageInit()」を呼び出します。これらの関数のコードを作成する必要があります。
これらの例は、レポート・ハンドラーで想定される複雑なケース全体の、わずか一部に対処できるに過ぎません。詳しくは、JasperReports の資料を参照してください。
handler handlerName type jasperReport
// Use Declarations
use usePartReference;
// 定数宣言
const constantName constantType = literal;
// Data Declarations
identifierName declarationType;
// 事前定義された Jasper コールバック関数
function beforeReportInit()
end
function afterReportInit()
end
function beforePageInit()
end
function afterPageInit()
end
function beforeColumnInit()
end
function afterColumnInit()
end
function beforeGroupInit(stringVariable string)
end
function afterGroupInit(stringVariable string)
end
function beforeDetailEval()
end
function afterDetailEval()
end
end
handler my_report_handler type jasperReport
// Data Declarations
report_title String;
// Jasper コールバック関数
function beforeReportInit()
report_title = getReportParameter("ReportTitle");
end
end
handler my_report_handler type jasperReport
// Data Declarations
item_count int;
// Jasper コールバック関数
function beforeDetailEval()
item_count = getReportVariableValue("itemCount");
end
function afterDetailEval()
setReportVariableValue("itemCount", (item_count + 1));
end
end
レポート・ハンドラー内の変数型は、XML ソース・ファイル内の変数型と一致させる必要があります。handler my_report_handler type jasperReport
// Data Declarations
employee_first_name String;
// Jasper コールバック関数
function beforeColumnInit()
employee_first_name = getFieldValue("fName");
end
end
handler my_report_handler type jasperReport
// Data Declarations
customer_array customerRecordType[];
c customerRecordType;
// Jasper コールバック関数
function beforeReportInit()
customer ReportData;
//Customer サブレポートの ReportData オブジェクトを作成する
c.customer_num = getFieldValue("c_customer_num");
c.fname = getFieldValue("c_fname");
c.lname = getFieldValue("c_lname");
c.company = getFieldValue("c_company");
c.address1 = getFieldValue("c_address1");
c.address2 = getFieldValue("c_address2");
c.city = getFieldValue("c_city");
c.state = getFieldValue("c_state");
c.zipcode = getFieldValue("c_zipcode");
c.phone = getFieldValue("c_phone");
customer_array.appendElement(c);
customer.data = customer_array;
addReportData(customer, "saveCustomer");
end
end
<jasperReport name="MasterReport" ... scriptletClass="subreports.my_report_handler">
...
<subreport>
<dataSourceExpression>
<![CDATA[(JRDataSource)(((subreports.SubReportHandler)
$P{REPORT_SCRIPTLET}).getReportData( new String("saveCustomer")))]]>;
</dataSourceExpression>
<subreportExpression class="java.lang.String">
<![CDATA["C:/RAD/workspaces/customer_subreport.jasper"]]>;
</subreportExpression>
</subreport>
...
</jasperReport>
handler my_report_handler type jasperReport
function hello () returns (String)
return("Hello, world!");
end
end
<jasperReport name="MasterReport" ... scriptletClass="my_package.my_report_handler">
...
<summary>
<band height="40">
<textField>
<reportElement positionType="Float" x="0" y="20" width="500" height="15"/>
<textElement textAlignment="Center">
<font reportFont="Arial_Bold" size="10"/>
</textElement>
<textFieldExpression class="java.lang.String">
<![CDATA[((my_package.my_report_handler)$P{REPORT_SCRIPTLET}).hello()]]>
</textFieldExpression>
</textField>
</band>
</summary>
...
</jasperReport>
「Hello, world!」という句がレポートの末尾に印刷されます。