Scriptlet

来源:互联网 发布:maya软件大小 编辑:程序博客网 时间:2024/05/23 15:34
 What is a Scriptlet?
A Script is a Java Class that extends one of the two following classes:
  • JRDefaultScriptlet
  • JRAbstractScriptlet


The sample extends the JRDefaultScriptlet. The difference between the two is with JRAbstractScriptlet a developer must implement all the abstract methods.
By extending JRDefaultScriptlet a developer is only required to implement that methods he/she needs for their project.
Once the Scriptlet has been referenced in the report, during the Filling stage of the Report Life Cycle, the JasperReports API will ensure to call the appropriate methods within the Scriptlet.
It is within these methods you will place your own logic to manipulate data in the report.

简言之,就是提供自定义操作(赋值,特殊运算处理等)!

例子:

例如某个变量AllCities需要特殊操作

1、在jrxml文件中,声明AllCities变量的时候,一定要将calculation设为"System"

如下所示:

<variable name="AllCities" class="java.lang.String" calculation="System"/>

2、在jrxml文件的标签jasperReport中,引用所使用的的scriptlets,如下所示:

scriptletClass="scriptlets.WebappScriptlet">

3、具体逻辑写到scriptlets的方法中

这些方法都是针对一些事件来写的!

 

原创粉丝点击