Jasper Report v1.0用户手册中文版

 

Jasper Report 用户手册
version1.0
 
 
 
作者:薛笛
 
EMail [email protected]
严正声明:本来我在以前把JasperReport1.0的用户文档由中文译成了英文,花了两周多时间写了几万字,并把它贴到了CSDNBlog上,并凡是要翻译完的PDF文档的朋友我都尽量给邮过去。但是最近我发现问我要文档的人总管我叫“良子大哥”,我开始还不明所以,后来一查才知道CSDN上有个叫良子的人把我翻译的东西整理了一下,调整了一下格式变成了他的作品,上面压根就没提我,但是里面的注明的索要文档PDF版的E-Mail[email protected])却是还是我的所以别人还是问我要PDF文档!!这令我十分不爽。本来嘛,我想公开大家看是件好事,但你不能连个转载标志也不写啊!??这行为不是明抢吗,做人不能这样啊?但是今天我终于想通了,我好歹也念过这么多年书,不能和他一般见识,最终又重新把它贴出来,不过还是希望不要有人再这么做。
 
Jasper Report用户手册... i
version1.0. i
1     简介... 1
2     API概览... 2
Class net.sf.jasper.engine.design.JasperDesign. 2
Class net.sf.jasper.engine.JasperReport4
Class net.sf.jasper.engine.JasperCompileManager4
Class net.sf.jasper.engine.JasperPrint4
Interface net.sf.jasper.engine.JRDataSource. 4
Class net.sf.jasper.engine.JRResultSetDataSource. 5
Class net.sf.jasper.engine.data.JRTableModelDataSource. 5
Class net.sf.jasper.engine.JREmptyDataSource. 5
Class net.sf.jasper.engine.JasperFillManager5
Class net.sf.jasper.engine.JRAbstractScriptlet6
Class net.sf.jasper.engine.JRDefaultScriptlet6
Class net.sf.jasper.engine.JasperPrintManager6
Class net.sf.jasper.engine.JasperExportManager7
Class net.sf.jasper.engine.JasperRunManager7
Class net.sf.jasper.view.JRViewer7
Class net.sf.jasper.view.JasperViewer7
Class net.sf.jasper.view.JasperDesignViewer7
Class net.sf.jasper.engine.util.JRLoader7
3     主要的任务和过程... 8
3.1      XML解析... 8
3.2      编译报表设计(Report Designs)9
3.3      Report Design 预览... 12
3.4报表装填(Filling Report... 13
3.5      查看报表(Viewing Reports... 15
3.6      打印报表... 15
3.7      导出报表... 16
3.8      对象的载入和保存... 16
4     报表设计(Report Designs... 17
4.1      DTD Reference. 17
4.2      XML 编码... 18
4.3      报表属性... 19
Report Name. 19
Column Count(列数)... 20
Print Order(打印顺序)... 20
Page Size(页面大小)... 21
Page Orientation(默认设置为Portrait... 21
Page Margins(页边距)... 21
Empty Data Source Behavior22
Scriptlet Class22
5     报表数据(Report Date... 23
5.1      表达式(expressions... 23
5.2      参数(Parameters... 24
参数名... 25
参数类型... 25
Prompting for Parameter values26
参数的默认值(parameter default value... 26
5.2.1    内置的报表参数... 27
5.3      Data Source(数据源)... 28
5.4      报表查询(Report Query... 30
5.5      字段(Field... 32
字段名(Field Name... 33
字段类型(Field Class... 34
字段描述(Field Description... 34
5.6      变量(Variables... 35
变量名(Variable Name... 35
变量类型(Variable Class... 35
重置类型(Reset Type... 36
Reset Group. 36
5.6.1    运算(Calculations... 36
5.6.2    内置的报表变量(Build-in Report Variables... 39
6 Report Sections41
6.1 Main Report Sections42
6.2 Data Grouping. 43
Group Name. 44
Group Header44
Group Footer44
7 Scriptlets45
8 Report Elements46
Absolute Position. 46
Relative Position. 47
Element Size. 47
Element Color47
8.1 Text Elements51
8.1.1 Fonts and Unicode Support51
8.1.2 Static Texts55
8.1.3 Text Fields56
8.2 Graphic Elements58
8.2.1 Lines59
8.2.2 Rectangles60
8.2.3 Images60
8.2.4 Charts and Graphics62
8.3 Hyperlinks63
8.4 Element Groups64
9 Subreports65
9.1 Subreport Parameters67
9.2 Subreport Data Source. 68
10 Advanced JasperReports68
10.1 XML Report Designs Loading and Writing. 68
10.2 Implementing Data Sources69
10.3 Customizing Viewers69
10.4 Exporting to New Output Formats70


 

1     简介
JasperReport是一个强大、灵活的报表生成工具,能够展示丰富的页面内容,并将之转换成PDF,HTML,或者XML格式。最重要的是它是开源的,这给我们带来很大方便,但是文档却要钱,让人不爽。不过人总要生存,再说,做这么一个好东西,用户总不能一点代价也不付(虽然对于中国普通程序原来说太贵了点)。它还有一个相关的开源工程—IReport,这是一个图形化的辅助工具,因为JasperReport仅提供了可使用的类库而未提供更好的开发工具,IReport的出现解决了这一难题。它们配合使用将会更大程度的提高效率。
该库完全由Java写成,可以用于在各种Java应用程序,包括J2EE,Web应用程序中生成动态内容。它的主要目的是辅助生成面向页面的(page oriented),准备付诸打印的文档。
JasperReport借由定义于XML文档中的report design进行数据组织。这些数据可能来自不同的数据源,包括关系型数据库,collections,java对象数组。通过实现简单的接口,用户可以将report library插入到订制好的数据源中,在以后我们将提到有关内容。
其实这是一份JasperReport Ultimate Guide的简单翻译以及我的理解和例子。在最后,我将描述一个我正在做的工程,将其中用到的相关信息贡献出来。我这么做是因为当我在学这个类库的时候苦于很少有相关的中文文档,诱惑语焉不详,希望其他人不再受苦。这个文档将分几次贴出来,与原文档的章节相对应。这份文档的Word形式将在全部完成之后放在我的公开邮箱中与各位共享。我的EMail是[email protected]有什么意见或想法请与我联系。
闲言少叙,进入正题。
2       API概览
上图为一个生成报表并打印(导出)的全过程。我将会把涉及到的重要的类进行一一说明。
Class net.sf.jasper.engine.design.JasperDesign
这是一个未经加工的报表实例,供JasperReport Library使用。这个类可以在JasperReport类库内置的XML解析器对XML report design进行解析处理之后得到。如果你的程序不想对直接XML文件进行操作,在例子noxmldesign中有不使用XML设计文件而动态生成这个类的方法。我们稍稍看看这个例子:
import 略
public class NoXmlDesignApp
{
private static JasperDesign getJasperDesign() throws JRException
{
//JasperDesign定义JasperDesign的头信息
              JasperDesign jasperDesign = new JasperDesign();
              jasperDesign.setName("NoXmlDesignReport");
              .剩余略
             
              //Fonts定义使用到的字体
              JRDesignStyle normalStyle = new JRDesignStyle();
              normalStyle.setName("Arial_Normal");
                           
              //Parameters 定义Parameters的内容—这个内容以后会提到
              JRDesignParameter parameter = new JRDesignParameter();
              parameter.setName("ReportTitle");
              parameter.setValueClass(java.lang.String.class);
              jasperDesign.addParameter(parameter);
 
              parameter = new JRDesignParameter();
              parameter.setName("OrderByClause");
              parameter.setValueClass(java.lang.String.class);
              jasperDesign.addParameter(parameter);
 
              //Query 定义查询
              JRDesignQuery query = new JRDesignQuery();
              query.setText("SELECT * FROM Address $P!{OrderByClause}");
              jasperDesign.setQuery(query);
 
              //Fields
              JRDesignField field = new JRDesignField();
              field.setName("Id");
              field.setValueClass(java.lang.Integer.class);
              jasperDesign.addField(field);
 
              //Variables 定义变量
              JRDesignVariable variable = new JRDesignVariable();
              variable.setName("CityNumber");
              variable.setValueClass(java.lang.Integer.class);
              variable.setResetType(JRVariable.RESET_TYPE_GROUP);
 
              //Groups 定义组
              group.setMinHeightToStartNewPage(60);
              expression = new JRDesignExpression();
              //余下定义一个文档的其他内容,这里省略
             
              return jasperDesign;
       }
从getJasperDesign()方法我们可以看出,这个应用程序并没有从XML文件里面将report design提取出来在生成JasperDesign类,而是直接利用JasperDesign提供的函数生成了一个报表设计。这样做的原因是基于灵活性的考虑,你可以在程序中随时动态生成报表,而不需要去从硬盘或网络中读取XML设计文件。但通常我不这么做,因为比较麻烦,而且要对JasperReport的每个元素都非常熟悉才行。
Class net.sf.jasper.engine.JasperReport
这个类的实例包含了一个经过编译的report design对象。生成它的时机是对报表编译之后,但尚未对其填入数据的时候。编译过程中,JasperReport需要生成一个临时的类文件,用以保存report expression,如变量表达式,文本,图像表达式,组表达式等等。这个临时的Java Source File是被动态编译的,编译器使用的是JDK中用来执行应用程序的编译器类(compiler class)。如果 tools.jar不在classpath中,编译过程将采用javac.exe来进行后台编译。编译后所得的字节码保存在JasperReport类中,用来在执行期装填数据(filling the report with data)和给表达式赋值(evaluate various report expression)。
Class net.sf.jasper.engine.JasperCompileManager
这是一个上面提到的与编译有关的类。利用它提供的一些方法,你将有能力编译从本地硬盘或一个Input Stream获得的XML report;还可以通过传给JasperCompileManager一个JasperDesign类,来对内存中的report design进行编译—功能很强大。
Class net.sf.jasper.engine.JasperPrint
当一个报表已经装填好数据之后,这个文档就以JasperPrint类的实例出现。这个类可以直接用JasperReport内置的viewer进行查看,也可以序列化到硬盘以备后用,或者发送到网上去。这个类的实例是报表装填过程后的产物,它可以被JasperReport类库中的导出方法导出成各种流行的格式—PDF,HTML,XML等等。
Interface net.sf.jasper.engine.JRDataSource
这个类与报表的数据源有关。只要能够恰当的实现他的一些接口,用户就可以在报表中使用各种数据源,在报表装填的时候由报表引擎负责对数据进行解释和获取。当报表装填的时候,报表引擎都会在后台生成或提供一个该接口的实例。
Class net.sf.jasper.engine.JRResultSetDataSource
这是一个JRDataSource的缺省实现,因为很多报表数据都来源于关系数据库,所以JasperReport缺省包含了这个外覆(wrap)了java.sql.ResultSet对象的实现。
这个类可以用来包裹(wrap)用以对报表进行装填的、已经载入的结果集,也可以被报表引擎用来包裹通过JDBC执行完查询后所得的数据----非常有用。
Class net.sf.jasper.engine.data.JRTableModelDataSource
顾名思义,这个类用于包裹java.swing.table.TableModel类中的数据,它也是实现了JRDataSource接口,用于在Java Swing程序中使用已经被载入到table中的数据来生成报表。
Class net.sf.jasper.engine.JREmptyDataSource
这是JRDataSouce接口的最简单实现,这个类用在不需要显示数据源数据而从参数中获取数据的报表和仅需要知道数据源中的实际行数(number of virtual rows)的报表中。
JasperReport自带的例子:fonts,images,shapes和unicode中使用这个类对报表进行装填,来模拟没有任何record的数据源,这时所有的field都为null。例如:
JasperRunManager.runReportToPdfFile(fileName, null, new JREmptyDataSource());
Class net.sf.jasper.engine.JasperFillManager
这个类用来实现报表的数据装填。这个类提供了很多方法来接受各种类型的report design--可以是一个对象,一个文件,或一个输入流。它的输出结果也是多样的:file,Object,output Stream。
report的装填引擎需要接收一个可以从中获取数据和value的数据源作为报表参数。参数值(Parameters value)通常使用Java.util.Map来提供,里面包含的KEY是报表的参数名。
数据源可以通过两种方式提供,这取决于你的解决方案:
通常情况下,用户应该提供一个JRDataSource对象,例如我前面提到的那些。
但是大多数的报表都是采用关系数据库中的值来装填数据,所以JasperReport拥有一个内置的缺省行为—让用户在报表设计的时候提供一个SQL查询。在运行期,这个查询将被执行以用来从数据库中获取要装填的数据。在这种情况下,JasperReport仅需要一个java.sql.Connection对象来取代通常的数据对象。JasperReport需要这个连接对象来连接数据库管理系统并执行查询操作。
在查询结束之后,JasperReport将自动生成一个JRResultSetDataSource,并将它返回给报表装填过程。
Class net.sf.jasper.engine.JRAbstractScriptlet
这个类同样用于报表装填期间,用户可以自己定义一些代码,并由报表引擎在装填过程中执行。这些用户代码可以处理报表数据操作,或在一些定义好的时刻执行,例如page,列,或组的分割处。
Class net.sf.jasper.engine.JRDefaultScriptlet
这是一个非常方便的JRAbstractScriptlet的子类。通常情况下你应该选择继承这个类。
Class net.sf.jasper.engine.JasperPrintManager
这个类用户提供打印方法,用户可以将整个文档或部分文档传递给它,也可以选择是否显示打印Dialog,这在他的API文档中可以找到,这里不再赘述。
Class net.sf.jasper.engine.JasperExportManager
顾名思义,这个类负责文档的导出。这个类的具体信息详见API文档。非常明显和清除,没什么好解释的,Just use it即可。
Class net.sf.jasper.engine.JasperRunManager
有时,我们仅仅需要构造一个流行的文档格式,例如PDF,或HTML,而不需要将装填过程后生成的JasperPrint对象保存到硬盘或其他中间媒体上。这时,可以使用这个类来直接将装填过程生成的文档导出到所需的格式。
Class net.sf.jasper.view.JRViewer
这是一个基于Swing的应用程序,你可以将它视为一个独立组件,用来进行打印预览。用户可以继承这个类,来构造满足自身要求的预览程序。
Class net.sf.jasper.view.JasperViewer
这个类更像是使用JRViewer的教学组件,它演示了一个Swing应用程序如何装在并显示报表。
Class net.sf.jasper.view.JasperDesignViewer
这个类用于报表的设计期间,用来预览报表模版。它仅作为一个开发工具存在于类库中。
Class net.sf.jasper.engine.util.JRLoader
装载器用于报表生成的各个主要阶段—编译,装填等等。用户和引擎都可以利用这个类来装载所需的序列化对象如file,URLs,intput stream等等。这个类最令人感兴趣的函数当属loadOnjectFromLocation(String location)。当用户使用这个类从指定地点装载对象的时候,该函数将首先将location解释为一个合法的URL,如果解析失败,函数将认为所提供的location是硬盘上的一个文件名,并将试图读取它。如果在指定地点没找到文件,它将通过classpath定位一个相应于该location的资源,所有努力失败之后,将抛出异常。
3       主要的任务和过程
这一节我们将看到对你的XML报表设计进行分析,编译,装填数据,预览结果和导出到其他格式的过程。
3.1    XML解析
JasperReport使用SAX2.0 API对XML文件进行解析。然而,这并不是必须的,用于可以在执行其自行决定使用哪一种XML解析器。
JasperReport使用org.xml.sax.helpers.XMLReaderFactory类的createXMLReader()来获得解析器实例。在这种情况下,就像在SAX2.0文档中说的那样,在运行期,把Java系统属性org.xml.sax.driver(这是属性的key)的值(value)设定为SAX driver类的全限定名是必要的。用户可以通过两种方法做到这一点,我稍后将解释全部两种方法。如果你想使用不同的SAX2.0XML解析器,你需要指定相应的解析器类的名字。
设置系统属性的第一种方法是在你启动Java虚拟机的时候,在命令行使用-D开关:java –Dorg.xml.sax.driver=org.apache.serces.parsers.SAXParser mySAXApp sample.xml
在JasperReport提供的所有例子中,都采用ANT构建工具来执行不同的任务。我们通过使用内置的 task中的元素来提供这一系统属性:
第二种设置系统属性的方法是使用java.lang.System.setProperty(String key, String value)
System.setProperty(“org.xml.sax.driver”,” org.apache.xerces.parsers.SAXParser”);
Jsp/compile.jsp和web-inf/class/servlets/CompileServlet.java文件提供了这方面的例子。
注:对于第二种方法,我要说些题外话。有关于JVM的系统属性(我们可以通过System.out.println(System.getProperty(“PropertyKey”)来查看),可以在运行期像上面说所得那样用System.setProperty(“propertyKey”,”propertyValue”);来进行设置。但是一旦JVM已经启动之后,其内建的系统属性,如user.dir,就不能再被更改。奇怪的是我们仍可以用System.setProperty()方法对其进行设置,而在用System.out.println(System.getProperty())方法进行查看的时候发现,其值已经更改为我们设置的值,但事实上我们设置的值不会起任何作用。所以对于内置的属性,我们只能通过-D开关在JVM执行之前进行设置。对于org.xml.sax.driver,由于它不是系统内建属性,所以仍然可以在JVM启动之后加以设置。更详细的信息可以参考王森的〈Java深度历险〉。
3.2    编译报表设计(Report Designs)
为了深成一个报表,用户需要首先生成报表的设计(report’s design),生成方法或采用直接编辑XML文件,或通过程序生成一个net.sf.jasper.engine.design.JasperDesign对象。本文中,我将主要采用编辑XML文件的方法,因为这种方法在目前是使用JasperReport类库的最好的方法,并且我们有机会更好的了解类库的行为。
先前提到过,XML报表设计是JasperReport用来生成报表的初级材料(raw meterial)。这是因为XML中的内容需要被编译并载入到JasperDesign对象中,这些对象将在报表引擎向其中填入数据之前经过编译过程。
注意:大多数时候,报表的编译被划归为开发时期的工作。你需要编译你的应用程序报表设计,就像你编译你的Java源文件一样。在部署的时候,你必须将编译好的报表,连同应用程序一起安装到要部署的平台上去。这是因为在大多数情况下报表设计都是静态的,很少用应用程序需要提供给用户在执行期编译的,需要动态生成的报表。
报表编译过程的主要目的是生成并装载含有所有报表表达式(report expression)的类的字节码。这个动态生成的类将会被用来在装填数据,并给所有报表表达式求值(evaluate)的时候使用。具体例子是,如果你用IReport生成一个报表名字叫SimpleSheetTest,它的XML设计文件名叫SimpleSheetTest.jrxml,同时和它在同一目录下IReport会自动生成一个文件名为SimpleSheetTest.java,里面主要是一些报表元素,如Field,Parameters,Variables的定义,以及一些求值表达式。当然,像上面提到的,这个文件在你直接使用JasperReport API的时候是看不到的,因为它是在执行期生成的一个Class。要想看到它的办法是:在IDE(JBuilder,Eclipse)中单步执行程序,在报表打印的阶段,你将能跟踪到这个类,它的名字就是“你的报表名.java”,按上面的例子就是SimpleSheetTest.java,这和IReport是一致的。当然也可以像下面说的那样,到生成这个类的临时目录里找到它。
在这个类生成过程之前,JasperReport引擎需要验证报表设计的一致性(consistency),哪怕存在一处验证检查失败都不会继续运行下面的工作。在下面的章节,我将会展示报表设计验证成功之后的状况。
对于这个包含了所有报表表达式(report expressions)的类的字节码,我们至少需要关心三个方面的内容:
l        临时工作目录(temporary working directory)
l        Java 编译器的使用
l        Classpath
 
为了能够编译Java源文件,这个文件必须被创建并且被保存到磁盘上。Java编译过程的输出是一个.class文件,这个包含所有报表表达式的类在这个工作目录里被创建并编译,这也是为什么JasperReport需要访问这个临时目录的原因。当报表的编译过程结束之后,这些临时的类文件将被自动删除,而生成的字节码将保存在net.sf.jasper.engine.JasperReport对象中。如果需要的话,这个类可以将自己序列化(serialized itself)并保存到磁盘上。这就是IReport的做法。
缺省情况下,这个临时工作目录就是启动JVM时的当前目录,这却取决于JVM的系统属性user.dir。通过更改系统属性jasper.report.compile.temp,用户可以很容易更改这个工作目录。在Web环境下,特别是当你不想让含有启动Web Server的批处理文件的目录和报表编译过程的临时工作目录混在一起的时候,修改这个属性就可以了。
上面提到的第二个方面涉及用来编译报表表达式类的Java编译器。首先,报表引擎将试图使用sun.tools.javac.Main类来编译Java源文件。这个类包含在tools.jar中,当且仅当这个jar文件在JDK安装目录下的bin/目录中,或在classpath中时,sun.tools.javac.Main才能正常使用。
如果JasperReport不能成功装载sun.tools.javac.Main文件,程序将动态执行java编译过程,就像我们通常用命令行那样,使用JDK安装目录下的bin/目录下的javac.exe。这就是为什么将JDK安装目录/lib/下的tools.jar文件copy到JasperReport工程的lib/目录下是一个可选的操作(optional operation)。如果tools.jar不在classpath中,JasperReport将显示错误信息并继续上面提到的操作。
当编译Java源文件的时候,最重要的事情莫过于classpath。如果Java编译器不能在指定的classpath中找到它试图编译的所有相关类的源文件,则整个过程将失败并停止,错误信息将在控制台显示出来。同样的事情也将发生在JasperReport试图编译报表表达式类的时候。所以,在runtime为编译过程提供正确的classpath是非常重要的。例如,我们我们需要确认在classpath中,我们提供了在报表表达式中可能用到的类(custom class)。
在这个方面也有一个缺省的行为。如果没有为编译report class特殊指定classpath,引擎将会使用系统属性java.class.path的值来确定当前的JVM classpath。如果你指定了系统属性jasper.reports.compile.class.path的值,你可以用你定义的classpath来覆盖缺省行为。
大多数情况下,编译一个report只需要简单的调用JasperReport类库中的JasperCompileManager.compileReport(myXmlFileName);即可。调用之后将生成编译好的report design并存储在.jasper文件中,这个文件将会保存在和提供XML report design文件相同的目录中。
3.3    Report Design 预览
JasperReport类库并没有提供高级的GUI工具来辅助进行设计工作。但是目前已经有至少4个project试图提供这样的工具。然而,JasperReport本身提供了一个很有用的可视化组件来帮助报表设计者在编译的时候预览报表设计(其实不如直接用IReport方便)。
net.sf.jasper.view.JasperDesigner是一个基于Swing的Java应用程序,它可以载入并显示XML形式或编译后的报表设计。尽管它不是一个复杂的GUI应用程序,缺乏像拖拽可视化报表元素这样的高级功能,但是它仍然是一个有用的工具(instrument)。所有JasperReport工程提供的例子都利用了这个报表查看器(report viewer)。
如果你已经安装了ANT(别告诉我你不知道什么是ANT),想要查看一个简单的报表设计(JasperReport工程所带例子),你只需要到相应的文件夹下输入如下命令:
〉ant viewDesignXML    或者    〉ant viewDesign
如果你没安装ANT,要达到上面的效果就不是很容易,因为JasperReport本身需要一些其他辅助的jar包(在JasperReport安装目录/lib下),在运行的时候,你需要把这些jar包都包含到你的classpath里面,并且正确设计系统属性,如上面提到的org.xml.sax.driver。我可以展示一下在windows下的例子:
>java -classpath ./;../../../lib/commons-digester.jar;
../../../lib/commons-beanutils.jar;../../../lib/commons-collections.jar;
../../../lib/xerces.jar;../../../lib/jasperreports.jar
-Dorg.xml.sax.driver=org.apache.xerces.parsers.SAXParser
dori.jasper.view.JasperDesignViewer -XML -FFirstJasper.xml
很麻烦吧?还是赶快弄个ANT吧。下面是预览之后的结果(其实用IReport更好)
3.4报表装填(Filling Report
报表装填(report filling)过程是JasperReport library最重要的功能。它体现了这个软件最主要的目的(main objective),因为这一过程可以自由的操作数据集(data set),以便可以产生高质量的文档。有3种材料需要装填过程中作为输入提供给JasperReport:
l        report design(report templet)
l        参数(parameters)
l        数据源(data source)
这一过程的输出通常是一个单一的最终要被查看,打印或导出到其他格式的文档。
要进行这一过程,我们需要采用net.sf.jasper.engine.JasperFillManager类。这个类提供了一些方法来让我们装填报表设计(report design),report design的来源可以是本地磁盘,输入流,或者直接就是一个已存在于内存中的net.sf.jasper.engine.JasperReport类。输出的产生是于输入类型相对应的,也就是说,如果JasperFillManager接到一个report design的文件名,装填结束后生成的report将会是一个放在磁盘上的文件;如果JasperFillManager收到的是一个输入流,则生成的report将会被写道一个输出流中。
有些时候,这些JasperFillManager提供的方法不能满足某些特定的应用的要求,例如可能有人希望他的report design被作为从classpath中得到的资源,并且输出的报表作为一个文件存放在一个指定的磁盘目录下。遇到这种情况时,开发人员需要考虑在将报表设计传递给报表装填过程之前,用net.sf.jasper.engine.util.JRLoader类来装载report design对象。这样,他们就能获得像报表名这样的report design属性,于是开发者就能生成最终文档的名字(construct the name of the resulting document),并将它存放到所需的位置上。
在现实中,有许多报表装填的情境(scenarios),而装填管理器仅试图覆盖其中最常被使用到的部分。然而对于想要自己定制装填过程的人来说,只要采用上面所说的方法,任何开发者都可以达到满意的结果。
报表参数通常作为java.util.Map的value提供给装填管理器,参数名为其键值(key)。
作为装填过程所需的第三种资源—数据源,有如下两种情况:
通常,引擎需要处理net.sf.jasper.engine.JRDataSource接口的一个实例,通过这个实例,引擎可以在装填过程中获取所需数据。JasperFillManager提供的方法支持所有的JRDataSource对象(这是一个Interface,上面一章提到过它的常用实现)。
然而,这个管理器还提供一些接受java.sql.Connection对象作为参数的方法集,来取代所需的数据源对象。这是因为在很多情况下,报表生成所需的数据都来源于某个关系型数据库中的表(table)。
在报表中,用户可以提供SQL查询语句来从数据库中取回报表数据(report data)。在执行期,engine唯一需要做的是获得JDBC connection对象,并使用它来连接想要连接的数据库,执行SQL查询并取回报表数据。在后台,引擎将使用一个特殊的JRDataSource对象,但是它对于调用它的程序来说是透明的。
JasperReport工程提供了相关的例子,它们采用HSQL数据库服务器(在工程文件中,有一个相应的文件夹),要运行这些例子你需要首先启动该服务器,方法是:在/demo/hsqldb目录下输入如下命令:>ant 或者 >ant runServer
没装ANT就麻烦点:>java -classpath ./;../../lib/hsqldb.jar org.hsqldb.Server
一下代码片断显示了query例子是如何装填数据的:
//Preparing parameters
Map parameters = new HashMap();
parameters.put("ReportTitle", "Address Report");
parameters.put("FilterClause", "'Boston', 'Chicago', 'Oslo'");
parameters.put("OrderClause", "City");
//Invoking the filling process
JasperFillManager.fillReportToFile(fileName, parameters, getConnection());
3.5    查看报表(Viewing Reports
报表填充阶段的输出通常是一个JasperPrint对象,如果把它保存在磁盘上,通常以一个.jrprint文件的形式存在。JasperReport拥有一个内置的查看器,用来查看用内置的XML导出器(XML exporter)获得的XML格式的报表文件。这个查看器就是以前提到过的net.sf.jasper.niew.JRViewer—一个基于Swing的应用程序组件,用户可以通过继承这个类来定制自己所需的查看器。JasperReport工程中自带的例子webapp中,你可以阅读JRViewerPlus类的代码来获取进一步内容。
注意: JasperViewer 更像是一个教人们如何使用 JRViewer 组件的演示程序,这里要注意一点,当你调用 JasperViewer viewReport() 方法来显示报表时,如果你关闭了预览 Frame ,整个应用程序将会随之结束,因为这个函数最后调用了 System.exit(0) ;你可以通过继承这个类,并重新在你的 Viewer 里注册 java.awt.event.WindowListener 来避免这一情况的发生。
3.6    打印报表
JasperReport类库的主要目标,就是生成可打印的文档。而且多数应用程序生成的报表都是需要落实(或打印)到纸张上。我们可以用net.sf.jasper.engine.JasperPrintManager来打印JasperReport生成的文档。当然,报表也同样可以在被导出到其他格式如PDF,HTML之后再被打印。通过JasperPrintManager提供的方法,我们可以打印整个文档,打印单个文档或打印某一范围内的文档,可以显示打印对话框也可以不显示。下面的例子演示了不显示对话框,打印整个文档的方法:JasperPrintManager.printReport(myReport,false);
这个例子显示了如何打印5-11页的文档,同时显示打印对话框:net.sf.jasper.engine.JasperPrintManager.printPages(myReport,4,10,true);
3.7    导出报表
在一些应用程序环境下,将JasperReport生成的文档从其特有的格式导出到其他更为流行的格式如PDF,HTML是非常有用的。这样一来,其他人就可以在没有安装JasperReport的情况下查看这些报表,特别是当这些文档要通过网络发送出去的时候。
JasperReport提供了JasperExportManager类来支持此项功能。这项功能将会在以后不断加入对新的格式的支持。目前,JasperReport主要支持导出PDF,HTML和XML类型的文档,下面是导出的代码片断:JasperExportManager.exortReportToHtmlFile(myReport);
注意:想要将自己的报表导出到其他格式的用户,需要实现 JRExporter 的接口,或继承相应的 JRAbstractExporter 类。
3.8    对象的载入和保存
当使用JasperReport的时候,你经常会与序列化的对象,如以编译的报表设计,或已生成的报表打交道。有时,你需要手动载入从不同的source如input stream或你用类库核心功能(lib’s core functionality)产生的序列化类。JasperReport提供了两个特殊的工具类来提供上述操作的能力,这些类通常供报表引擎自己使用:
net.sf.jasper.engine.util.JRLoader
net.sf.jasper.engine.util.JRSaver
       第一个类提供了一些方法让我们能够从不同类型的数据源如文件,URL,input stream和classpath里面获取序列化对象。最令人感兴趣的方法是loadObjectFormLocation(String)。它已经在上一章中介绍过了,这里不再赘述。
与上面的对象载入工具相反的部分是JRSaver类,它可以帮助程序员将自己的类序列化之后存放到本地磁盘或通过Output Stream发送到网络上去。
有时,开发人员可能想要载入已经生成好的report,或最终的已经被导出到XML格式的JasperReport文档,这与上面所说的直接load序列化对象有所不同。这时,我们需要载入的是将载入的XML内容进行编译,并生成JasperPrint对象,而并非仅仅是载入序列化对象。这时,我们可以通过net.sf.jasper.engine.xml.JRPrintXmlLoader类的一些静态方法,通过编译从XML文件中读取的内容构建出一个位于内存中的文档对象。
4       报表设计(Report Designs
报表设计体现了一个模版,JasperReport引擎利用这个模版将同台生成的内容传递给打印机,屏幕或Web。存储在数据库中的数据在报表装填的过程过被组织起来,根据已有的报表设计来获得可以进行打印的,面向页面的(page oriented)文档。
总而言之,一个报表设计包含了所有的结构相关信息和将数据提供给报表所涉及的各个方面。这些信息涉及将在文档中显示出来的各种text或图像元素的位置和内容,自定义计算(custom calculation),数据组织,报表生成时的数据操作,等等。
报表设计通常都定义在一个拥有特殊格式的XML文档中,并且在被填充数据之前要经历JasperReport的编译过程,有关于这个XML文档的详细信息我们将在以后说明。然而JasperReport也允许用户通过JasperReport提供的API构造in-memory报表对象,例程noxmldesign就是很好的例子,但是我们通常不这么用。
4.1    DTD Reference
当使用XML文件进行报表设计的时候,JasperReport将使用内置的DTD文件来验证其受到的XML内容的有效性。如果XML验证通过,则说明所提供的报表设计符合JasperReport所需要的XML结构和语法规则,其引擎能够生成经过编译的report design。
有效的XML文档总是在验证时指向JasperReport的内部DTD文件。如果没有提供DTD文档的引用,报表的编译过程将会突然结束。这对所有人来说都是一个负担,因为DTD引用通常是相同的,并且这些引用可能会简单的被从以前的报表设计中copy过来。在一开始,你需要将这个引用从给定的例子中copy过来。
正如以前说的一样,报表引擎仅能识别指向其内部DTD文件的的引用。你不能随便从类库的源文件中将那些DTD文件copy到别的地方,再在你的报表设计文件中文件中指向你copy的那些DTD文件。如果你想那样做的话,你将需要调整类库中某些类,包括net.sf.jasper.engine.xml.JRXmlDigester类的某些代码。如果你遇到像引擎无法找到其内部的DTD文件而导致的无法载入资源的问题,请确定你已经在使用外部DTD文件之前排除了所有可能发生的情况。遇到这样的问题是不太可能的,因为资源载入机制会随着时间不断改进。JasperReport只有两种合法的XML报表设计的DTD引用,他们是:
或者
XML报表的root元素是,下面是一个普通带JasperReport的样子:
4.2    XML 编码
当要生成不同语言的XML报表设计的时候,在XMl文件的首部的编码属性需要特别关注一下。缺省情况下,如果这个属性的值没被订制,则XML解析器将会使用“UTF-8”作为XML文件的编码格式。这一点是非常重要的,因为报表设计通常包含了静态的本地化text。对于大多数西欧语言来说,ISO-8859-1编码,也就是我们常说的LATIN1将会很好的处理如法语中重音符号的显示问题。
在编辑XML文件的时候,要找到某种特殊语言的编码类型,你可以查看XML document.FIXME
4.3    报表属性
我们上面已经看到,斯XML报表设计的根元素。这一节我将介绍报表设计对象的Property的细节以及这些属性所对应的XML attributes(为避免混淆,我将不提供Property和Attribute的中文而直接使用英文)。

鈥?鈥濆簲鐢ㄧ▼搴忎腑鐨勬湇鍔″櫒閿欒銆?hr width=100% size=1 color=silver>
杩愯鏃堕敊璇?/i>
璇存槑: 鏈嶅姟鍣ㄤ笂鍑虹幇搴旂敤绋嬪簭閿欒銆傛搴旂敤绋嬪簭鐨勫綋鍓嶈嚜瀹氫箟閿欒璁剧疆绂佹杩滅▼鏌ョ湅搴旂敤绋嬪簭閿欒鐨勮缁嗕俊鎭?鍑轰簬瀹夊叏鍘熷洜)銆備絾鍙互閫氳繃鍦ㄦ湰鍦版湇鍔″櫒璁$畻鏈轰笂杩愯鐨勬祻瑙堝櫒鏌ョ湅銆?

璇︾粏淇℃伅: 鑻ヨ浣夸粬浜鸿兘澶熷湪杩滅▼璁$畻鏈轰笂鏌ョ湅姝ょ壒瀹氶敊璇俊鎭殑璇︾粏淇℃伅锛岃鍦ㄤ綅浜庡綋鍓?Web 搴旂敤绋嬪簭鏍圭洰褰曚笅鐨勨€渨eb.config鈥濋厤缃枃浠朵腑鍒涘缓涓€涓? 鏍囪銆傜劧鍚庡簲灏嗘 鏍囪鐨勨€渕ode鈥濆睘鎬ц缃负鈥淥ff鈥濄€?br>
                

娉ㄩ噴: 閫氳繃淇敼搴旂敤绋嬪簭鐨? 閰嶇疆鏍囪鐨勨€渄efaultRedirect鈥濆睘鎬э紝浣夸箣鎸囧悜鑷畾涔夐敊璇〉鐨?URL锛屽彲浠ョ敤鑷畾涔夐敊璇〉鏇挎崲鎵€鐪嬪埌鐨勫綋鍓嶉敊璇〉銆?br>
                

">1

Report Name
每一个报表都必须有一个名字。这个名字是相当重要的,因为类库需要它来生成文件,尤其是当编译,装填,导出报表的默认行为被使用的时候,这个名的作用更为重要。这个名字是以元素的 name attribute的形式提供的,并且是强制必须填写。
Column Count(列数)
JasperReport允许生成每页的列数超过一列的报表,正如下面的图片,展示了拥有两列的报表:

鈥?鈥濆簲鐢ㄧ▼搴忎腑鐨勬湇鍔″櫒閿欒銆?hr width=100% size=1 color=silver>
杩愯鏃堕敊璇?/i>
璇存槑: 鏈嶅姟鍣ㄤ笂鍑虹幇搴旂敤绋嬪簭閿欒銆傛搴旂敤绋嬪簭鐨勫綋鍓嶈嚜瀹氫箟閿欒璁剧疆绂佹杩滅▼鏌ョ湅搴旂敤绋嬪簭閿欒鐨勮缁嗕俊鎭?鍑轰簬瀹夊叏鍘熷洜)銆備絾鍙互閫氳繃鍦ㄦ湰鍦版湇鍔″櫒璁$畻鏈轰笂杩愯鐨勬祻瑙堝櫒鏌ョ湅銆?

璇︾粏淇℃伅: 鑻ヨ浣夸粬浜鸿兘澶熷湪杩滅▼璁$畻鏈轰笂鏌ョ湅姝ょ壒瀹氶敊璇俊鎭殑璇︾粏淇℃伅锛岃鍦ㄤ綅浜庡綋鍓?Web 搴旂敤绋嬪簭鏍圭洰褰曚笅鐨勨€渨eb.config鈥濋厤缃枃浠朵腑鍒涘缓涓€涓? 鏍囪銆傜劧鍚庡簲灏嗘 鏍囪鐨勨€渕ode鈥濆睘鎬ц缃负鈥淥ff鈥濄€?br>
                

娉ㄩ噴: 閫氳繃淇敼搴旂敤绋嬪簭鐨? 閰嶇疆鏍囪鐨勨€渄efaultRedirect鈥濆睘鎬э紝浣夸箣鎸囧悜鑷畾涔夐敊璇〉鐨?URL锛屽彲浠ョ敤鑷畾涔夐敊璇〉鏇挎崲鎵€鐪嬪埌鐨勫綋鍓嶉敊璇〉銆?br>
                

">1

默认情况下,报表引擎生成每页一列的报表。
Print Order(打印顺序)
对于拥有超过一列的报表,为其提供列将被以什么顺序填充是很重要的。你可以使用printOrder attribute来进行设置。有如下两种情况:
n        Vertical Filling:这个选项将导致列是自顶向下被填充(printOrder=”Vertical”)
n        Horzontal:列将自左向右被填充(printOrder=”Horizontal”)
缺省设置将是printOrder=Vertical
Page Size(页面大小)
有两个attribute是用来提供要生成的文档大小的:pageWith,pageHeight。像所有其他显示元素位置和尺寸的attribute一样,这两个attribute是以像素为单位的。JasperReport采用Java默认的每英寸72点的设置。这意味着pageWith=”595”将大约是8.26英寸,这大概是A4纸的尺寸。
默认的纸张大小是A4纸:pageWith=”595” pageHeight=”842”
Page Orientation(默认设置为Portrait
orientation属性用来设置文档打印格式是“Portrait”还是“Landscape”。JasperReport允许用户在从“Portrait”切换到“Landscape”的时候调整液面的宽度和高度。我们先看一个例子:我们假定要生成一个A4纸的报表,采用“Protrait”格式。
pageWidth=”595” pageHeight=”842” orientation=”Portrait”
如果我们决定用A4纸的“Landscape”布局,首先要调整相应的页面宽度和高度:
pageWidth=”842” pageHeight=”595” orientation=”Landscape”
这是因为JasperReport需要确切知道它所要绘制的报表页的宽度和高度,而不只看我们提供的orientation属性,至少在报表装填的时候是这样。orientation属性仅在报表打印时有用,来通知打印机或某些exporters页面的orientation设置。
Page Margins(页边距)
一旦页面大小确定下来,用户就可以在生成报表的时候设定报表的边距。有四个属性来完成这项工作:topMargin,LeftMargin,bottomMargin和rightMargin。缺省的设置是上下边距20像素,左右边距20像素。
Column Size and Spacing(列宽和列间距)
一个报表可能含有多列,我们可以通过上面提到的columnCount属性得到报表列数。JasperReport需要知道列的宽度和列间距的大小。有两个属性用于这项工作:columnWidth和columnSpacing。当我们对报表设计进行编译的时候,编译器会对这项设置进行有效性检查(validation check)--看列的宽度和列间距是否符合给定的页面宽度和页边距。因为缺省的列数为一,所以缺省的列间距为0像素,并且缺省的列宽等于页面宽度减去左右边距所得的值。在上面A4的例子中,列宽即为555像素。
Empty Data Source Behavior
有时我们提供给我们的报表的数据源可能会没有任何record。whenNoDataType属性可以让你选择当所提供的数据源中没有数据的时候入和察看生成的报表。如下有三种不同的可能性,你可以任选其一:
l               Empty Document:生成的报表不含有页面(no page in it)。当你试图装载这样的文档(whenNoDataType=”NoPages”)的时候,Viewer 可能会抛出一个错误。
l               Blank page:表示生成的报表将仅含有一个空白页。(whenNoDataType=”BlankPage”)
l               All sections displayed:除了detail部分的其他部分将在生成的文档中显示出来。(whenNoDataType=”AllSectionNoDetail”)。
缺省的设置是whenNoDataType=”NoPages”。
              Title and Summary Sections Placement(标题和摘要的放置)
如果你想让title部分和summary部分在单独的一页里显示,你所需要做的事情就是让下面的一个或两个属性的值为“true”:isTitleNewPage,isSummaryNewPage。这两个属性缺省情况下为false。
注意 : 即使你选择了在最后一页的剩余部分显示 summary ,如果列数超过一列,并且第二列已经在最后一页出现的时候(没试过,等有机会试验一下),新的一页将会被自动生成。
Scriptlet Class
scirptletClass属性用于设置用于当前报表的scriptlet类的名字。在以后我会对Scriptlet进行详细讨论。如果你没为这个属性提供任何值,报表引擎将会使用net.sf.jasper.engine.JRDefaultScriptlet的实例。
5       报表数据(Report Date
当我们谈到报表装填过程的时候,有三样东西需要作为输入提供给报表引擎:报表设计(report design),参数值(parameter values)和报表的数据源(data source)。
在先前的章节,我们已经看到了有关报表设计的某些方面,现在我们要更加详细的关注其他两方面的内容:参数(parameter)和报表数据源。他们描绘了报表引擎在装填报表过程中所用到的仅有的数据来源。像你用其他报表工具所希望的一样,这些数据将会根据报表设计中的定义的模版(template)被组织起来,并被用来生成准备打印的、面向页面的文档。
5.1    表达式(expressions
表达式是JasperReport的一个非常有用的特性。他们可以用来声明执行各种执行各种计算(calculations)的报表变量(report variables),进行报表的数据组织,定制报表文本字段(text field)的内容或者进一步定制报表对象的appearance。
所有报表表达式基本上都是Java表达式,他们可以以特殊的语法引用报表参数( parameter),报表字段( field)和报表变量( variable)。在XML报表设计中,有一些用于定义表达式的元素:等等
因为所有的JasperReport表达式都是真正(real)的Java表达式,只要你用完整的类名(包括包名)来引用这些表达式,你就可以在任何class中使用他们。当你编译报表和装填数据的时候,你应该确定你在报表表达式中使用的类已经写入了classpath。
报表参数引用是通过$P{}序列引入的,例如:
      $P{ReportTitle}
这个例子假定我们在报表设计中有一个名为 ReportTitle的报表参数,这个参数是一个java.lang.String类。当报表进行装填的时候,文本字段将会显示这个参数的值。
为了在一个表达式中使用报表字段,字段名必须放在$F{}的括号中。例如,如果我们想要在一个文本字段中显示两个数据源字段的连接值(concatenated values),我们可以定义如下表达式:
      $F{FirstName} + “ “ + $F{LastName}
表达式可以更加复杂:
      $F{FirstName} + “ “ + $F{LastName} + “ was hired on “ +
   (new SimpleDateFormat(“MM/DD/YYYY”)).format($F{HireDate)) + “.”
正如你所看到的一样,参数、字段和变量引用都是通过用JasperReport的特殊语法从一个真正地Java对象中引入的。(实际上是一个JREvaluator对象,该对象是在运行其生成的动态对象,并不能在本地磁盘上见到它的身影,不过如果你使用iReport的话,你就可以在生成报表文件的同一目录下看到它的本来面目)
5.2    参数(Parameters
Parameters是传递给报表装填操作的对象引用。这些参数主要作用于把那些不能从报表数据源中获得的数据传给报表引擎。例如,我们可能要把执行报表装填过程的用户名字专递给报表引擎,如果我们想让它显示在报表上或者在我们想在报表的title上动态的改变它,我们就可以以参数的形式传给报表引擎。
我们可以用如下的方式定义参数:
这里所提供的报表参数值可以被用到各种报表表达式中,在报表SQL查询中,甚至可以用到报表的scriptlet类里。下面是构成参数定义的全部组件(XML元素):
参数名
name属性是一个强制属性。JasperReport的命名习惯和Java语言的命名习惯是类似的,这意味着参数名应该是一个单词,其中不含特殊字符(如分号)。
参数类型
报表参数的第二个强制属性是提供参数值的类型名。这个类型属性可以使任意的值,只要这个类型的名字在报表编译期和装填期能在classpath中找到即可。
Prompting for Parameter values
在GUI引用程序中,建立一个报表参数集,让用户在执行装填过程之前输入某些应用程序需要用户输入的报表参数是很有用的。可选参数isForPropting参数用来声明是否显示提示信息让用户输入某些参数。下面的例子中,我声明了一个文本参数,当需要用户输入参数值的时候,这个文本参数用来在一个已定制的对话框中描述需要用户输入什么样的参数。
Please type here the report comments if any
]]>
注意:相信大家都知道 内容 ]]> 表示“内容”将不被 XML 解析器解析,也就是说,你可以在“内容”里加入 XML 的特殊字符,如 > < 等等。
参数的默认值(parameter default value
通常参数值都是使用java.util.Map对象传给装填过程的,其中参数名作为Key。这样,你就不用每次都为每个参数提供一个value了—可以批量放到Map对象里一起传给装填管理器。如果你没有为参数提供一个value,引擎就认为它是null。但是如果你为它提供了一个默认值,则引擎将在你没提供这个参数值的情况下使用这个默认值。如果你在装填时没提供数据,下面的java.util.Date将在装填是被引擎使用来表示当天日期:
new java.util.Date()
在参数的默认表达式中,我们可以使用这个与定义的报表参数。
5.2.1 内置的报表参数
每一个报表设计中都含有一些与定义的报表参数,这些内置的参数的描述如下:
REPORT_PARAMETERS_MAP
这是一个内置的参数,这个参数总是指向一个java.util.Map对象,该对象保存了用户调用报表装填过程时传递给报表引擎的用户定的参数。
REPORT_CONNECTION
这个报表参数指向一个java.sql.Connection对象,这个对象被提供给报表引擎用来通过JDBC来执行SQL报表查询。将master报表使用的JDBC Connection对象传递给subreport是非常有用的,有关这方面信息请查看 subreport例子
REPORT_DATASOURCE
在报表装填的时候,我们可以或者直接由应用程序中提供,或由报表引擎从所提供的JDBC Connection在后台create而获得一个数据源。这个内置的参数允许我们在报表表达式中或scriptlet中访问报表数据源,而不论我们为什么要这么做。
REPORT_SCRIPTLET
即使报表不使用scriptlet,这个内置的参数仍将指向一个net.sf.jasper.engine.JRAbstracStriptlet实例,该实例实际是一个net.sf.jasper.engine.JRDefaultScriptlet对象。
但是当使用scriptlet时,报表装填过程所生成的这个指向scriptlet类实例的引用允许我们调用其中的某些特殊函数,使用或控制scriptlet对象在装填过程中已经准备好的数据。在scriptlet例子中你可以看到更详细的使用过程。
5.3    Data Source(数据源)
在进行报表装填的时候,JasperReport引擎迭代的从用户提供的数据源中提取record,并根据报表设计所提供的模版生成报表的各个部分(section)。通常情况下,引擎需要接收一个net.sf.jasper.engine.JRDataSource对象作为报表数据源。但是像我们即将看到的那样,当报表数据存储于关系型数据库的时候,JasperReport有了让用户提供一个JDBC链接对象来替代通常的数据源对象的特性。JRDataSource接口非常简单,如果我们想要实现它只需要实现下面两个方法:
public Boolean next() throw JRException;
public Object getFieldValue(JRField jrField) throw JRException
在报表装填的时候,next()方法将被报表引擎调用,迭代的从数据源中获取数据。第二个方法用来为每个在当前数据源记录(data source record)中的报表字段(report field)提供value。
       应当知道, 从数据源取得数据的唯一方法是使用report field。一个数据源对象更像是一个二维表,表中含有数据。这个二维表的行是一条一条的record,而每一列都映射为一个report field。所以我们可以在report表达式中使用数据源。JasperReport提供了一些缺省的JRDataSource实现,我们来具体看一下:
Class net.sf.jasper.engine.JRResultSetDataSource
这是一个非常有用的缺省实现,因为他外覆(wrap)了java.sql.ResultSet对象。由于多数报表的生成都采用关系数据库中存储的数据,所以这个类是被使用得最为广泛的数据源对象。然而在以下的两种情况下您可以不必在装填过程中自己生成这个对象:
如果你选择在你的报表中用SQL查询来获得在关系数据库的某个table中的数据,报表引擎将会通过执行给定的SQL查询并且将返回的java.sql.ResultSet外覆为一个net.sf.jasper.engine.JRResultSetDataSource实例来执行这项操作。引擎唯一需要的是一个java.sql.Connection对象来执行查询操作。这时你可以提供connection对象来作为通用数据源对象(usual data source object)。例子有:jasper,scriptlet,subreport和query。
当然你可以在应用程序中即JasperReport之外执行SQL查询。这样的话,你可以手动的外覆java.sql.ResultSet,再调用报表装填过程之前实例化这个数据源对象。当使用这种类型的数据源的时候,你需要为在result set中的每一列生命一个report field。report field的名字和类型必须和列的名字和类型匹配。
Class net.sf.jasper.engine.JREcptyDataSource
这个类主要用于当生成报表的数据不是来自数据源,而是来自参数或重要的仅是数据源中virtual records的数量的时候。例子fonts,images,shapes和unicode都使用了这个类来装填报表,来模拟数据源中没有一条记录,所有字段都为null的情况。
Class net.sf.jasper.engine.data.JRTableModelDataSource
这个JRDataSource接口的缺省实现外覆了javax.swing.table.TableModel对象,它可以用在Java Swing应用程序中从已经显示到屏幕上的table中得数据来生成报表。--我喜欢。
通常有两种方法来使用这种数据源:
通常,为了要从中取得数据,你需要为javax.swing.table.TableModel对象的每一列生命一个report field。但是有些情况下会出现问题,比如report field的命名需要遵照Java命名规范来声明变量,而table的列名则不需要。幸运的是,你仍然可以通过列的索引而不是它的名字来将report field与列进行映射。例如,一个列名为“Produce Description”不可能被映射到名为“Produce Description”的report field上,因为report field名中含有空格,这将引起一个编译错误。但是如果你知道这个列示table model对象的第三列(index=2),那么你就可以命名相应的字段“COLUMN_2”并无误地使用这一列的数据。例子有: datasource
Class net.sf.jasper.engine.data.JRBeanArrayDataSource
这个类外覆了一个JavaBeans数组,并且通过反射来获取report field的值。在这种数据源中,一个JavaBean对象描述了一条记录。如果我们有一个名为“ProductDescription”的report field,在获取这个字段的值的时候,程序将会试图通过反射机制调用一个当前JavaBeans对象中]名为getProductDescription()的方法。对于boolean字段,当调用 get前缀的属性不能返回其属性值的时候,程序将会试图使用 is前缀的方法来获得属性值。
Class net.sf.jasper.engine.data.JRBeanCollectionDataSource
这个类和上一个类非常类似,它也是使用反射机制和JavaBean命名规范,但是它外覆了一个java.util.Collection对象而不是一个JavaBean对象数组。在datasource例子中你可以看到进一步的用法。
5.4    报表查询(Report Query
为了要为报表装填数据,我们需要为报表引擎提供所需的数据,或者至少告诉它怎样去获取数据。JasperReport通常需要接受一个net.sf.jasper.engine.JRDataSource对象作为报表的数据源,同时作为更为强大的功能,JasperReport能直接用JDBC从关系数据库总获取数据。类库允许用户在他们的报表设计中提供SQL查询以便可以自运行期从数据库中提取数据。要做到这一点,你只需要在装填的时候为装填管理器的fillReport()方法提供一个java.sql.Connection而不是JRDataSource对象即可。
在报表中,可以使用元素来引入查询。如果这个元素存在,则出现在报表参数声明之后,报表field之前。
如下是一个SQL查询的例子:
为了更好的定制从数据库中取回的数据集(data set),一个重要的方面是在报表查询字符串中 报表参数的使用(use of report parameters)。在查询中,这些参数可能会像动态过滤器(dynamic filter)一样工作,它们用特殊的语法被引入进来为报表提供数据,很像report expression。
如下有两种在查询中的使用参数的方法:
1.      像通常的java.sql.PreparedStatement的参数那样使用,用如下语法:
SELECT * FROM Orders WHERE OrderID <= $P{MaxOrderID} ORDER BY ShipCountry
]]>
2.      有时,我们需要使用参数来动态更改SQL查询的某些部分,或将整个SQL查询作为参数提供给装填过程。在这种情况下,语法稍微有些不同,向下面的例子,注意 “!”
     
SELECT * FROM $P!{MyTable} ORDER BY $P!{OrderByClause}
]]>
在这个例子中,这个引入了参数值得特殊的语法确定了我们为这些参数所提供的值将会替代查询中的参数引用($P!{}的内容)。这些参数将被传给使用java.sql.PrepqredStatement对象的数据库服务器。
事实上,报表引擎首先处理$P!{}参数引用,通过使用他们的值来获取最重的SQL查询,并且仅当这件事完成之后,引擎才会将剩下的普通的$P{}参数引用传递给usual IN parameters。--实际上就是嵌套查询啦。
第二种用于SQL查询的参数引用允许你在运行期传递整个SQL查询语句:
$P!{MySQLQuery}
注意:你不能在参数值中再加入参数引用,也就是说,参数引用不能嵌套使用。
更详细的信息可以参看工程所带的例程:jasper,subreport,scriptlet,webapp以及最有学习价值的query
5.5    字段(Field
报表字段是从数据源到报表设计的数据映射的唯一途径。你可以应用报表字段在report表达式中使用数据源中的数据,或获得所需的输出。一旦定义了报表字段,你需要在报表填充的时候确认你所提供的数据源中提供了所有你声明的fields。
例如,如果你使用JRResultSetDataSource作为数据源,你需要确定在SQL查询结束之后所获得的ResultSet中的column包含你生命的全部fields。相应的列名和字段名必须完全相同,并且其数据类型也必须完全一致。
这是一个字段声明的语法,字段的声明需要对应于数据库表中的某一字段。我们来考虑一个Employee的例子,有如下表结构(structure):
报表字段需要像下面这样定义:
如果你定义的字段不能和ResultSet中的某一列相对应,则在运行期将会抛出异常(如果你用IReport,在编译时也会抛出异常)。然而执行SQL查询之后返回的结果集中包含的列不需要与报表字段一一对应(即列可以多于字段,只是在显示的时候不显示出来罢了)。
字段名(Field Name
元素的name属性是强制属性(即不能省略),你可以在表达式中通过它来引用该字段。字段名必须是一个单词,且不含有特殊字符,如点和分号。
字段类型(Field Class
这个属性描述了字段值的类型,缺省的类型是java.lang.String,还有其他可选类型如:
java.lang.Object
java.lang.Boolean
java.lang.Byte
java.util.Date
java.sql.Timestamp
java.lang.Double
java.lang.Float
java.lang.Integer
java.io.InputStream
java.lang.Long
java.lang.Short
java.math.BigDecimal
如果某些数据源含有一些自定义的类型,则该类型所对应的字段应该声明为java.lang.Object。但是与参数定义不同的是,你只能选择上述列表中的类型名。
字段描述(Field Description
当实现一个自定义数据源的时候跟,这一伴随着某个字段的附加的文本块是很有用的。你可以在字段描述中保存一个key或其他任何信息以便于在运行期从自定义数据源中取回字段值。通过使用可选的元素,你就可以轻松的越过字段名的约束(field naming conventions),在从数据源取数据的时候,使用字段描述而不是字段名来获取相应数据。
PERSON NAME
5.6    变量(Variables
报表变量是建立在报表表达式之上的一些特殊对象。他们是用表达式定义的,用来执行某些运算,来简化报表中频繁出现或使用某些项目(如页号,页码,某些列的累加和等等)。下面是它的定义语法:
可以看到,在这个语法中,一个变量可以引用其他变量,当且仅当被引用的变量已经在报表中被定义过。所以,在报表设计中,变量定义的顺序非常重要。
变量名(Variable Name
与字段名和参数名一样,元素的name属性是强制属性,报表引擎允许在报表表达式中通过这个这个名字来引用变量。变量名的命名规则与参数和字段的规则相同。
变量类型(Variable Class
每一个变量都有其类型,缺省为java.lang.String,然而只要你所选择的类型可以在classpath中找到,你就可以在报表编译期和填充期声明任何类型的报表变量。
重置类型(Reset Type
报表变量的值可以在每一次迭代(iteration)中被改变,但也可以在装填过程中的某一特定的时间(specified moments)通过它的初始的value表达式恢复其初始值。这一行为是由resetType属性控制的,这一属性规定了报表装填过程中当报表变量在何时需要重新进行初始化(或恢复到初始值)。该元素有五种选项值:
n        No Reset:变量将不会使用其initial value expression对自身进行初始化,而将仅报表从变量表达式中所求得的值(resetType=”None”)。
n        Report Level Reset 变量将在报表填充过程的起始阶段使用其初始化表达式初始化一次(resetType=”Report”)。
n        Page Level Reset 变量将在每一页的起始时被重新初始化(resetType=”Page”)。
n        Colunm Level Reset 变量将在每个新列的开始被初始化(resetType=”Column”)
n        Group Level Reset:变量将在每次resetGroup属性提供的break的地方被重新初始化(resetType=”Group”)。
缺省的属性为resetType=”Report”
Reset Group
如果存在的话,resetGroup属性包含了报表的组的名字并且仅与resetType=”Gropu”的resetType属性相关联。
5.6.1 运算(Calculations
像以上所提到的,变量能执行内置的计算类型(build-in types of calculation)。下面是元素的calculation属性的所有可能的值:
Calculation Nothing
这是变量执行的缺省计算。这意味着变量值在数据源的每次迭代时被重新计算(这里的计算只是简单的通过变量表达式给变量赋值)。
Calculation Count
在每次数据源的迭代的时候( 注:这里和之前我所说的数据源的迭代都是指:例如,在报表装填的时候,引擎执行 SQL 查询返回的 ResultSet 中含有若干记录,每次迭代都是指从 ResultSet 中获得一条记录,并将这条记录的值赋给已经声明的字段),一个计数(count)变量将会把用主表达式(main expression)计算所得的非空(not null)值累加起来。计数变量(Count variables)必须是一个数字类型的变量,但是它的主表达式可以是一个非数字型表达式(non-numeric expression),因为报表引擎不关心表达式类型,而仅仅将这些非空的返回值得数目累加起来—就好像一个累加器一样。
只有变量的初始值表达式必须是数字型的,并且需要和变量的类型相同,因为这个值将会在初始化的时候被直接赋给变量。
Calculation Sum
如果你选择了这种类型的计算,报表引擎将会把变量主表达式的返回值累加到一起,但需要注意的是变量必须是数字类型的。我们不能计算一个java.lang.String或java.util.Date类型的报表变量。
Calculation Average
对于数据源中的每一条记录,报表引擎可以计算通过对变量表达式求值所得的一些列结果的平均值(series of values obtained by evaluating the variable’s expression)。这种类型的计算的也只能是数字类型的变量。
为了完成计算平均值的操作,报表引擎将在后台了创建一个helper报表变量来计算values的累加和(sum),并用它来计算这些value的均值。这个helper sum variables的命名规则是在对应的变量名后面加上“_SUM”前缀。例如,如果你声明了一个数字类型的变量,名为MyAverageVariable,报表引擎将会建立一个MyVerageVariable_SUM的变量来帮助计算均值。如果你需要的话,你可以在其他的报表表达式中使用这个helper变量,就像你使用其他你声明的变量一样。
为了计算均值,报表引擎同时也需要一个计数变量(count variable)。但是对于“Report”,“Page”和“Column”的reset type,引擎将使用我们在下一节即将看到的内置的计数变量。对于resetType=“Group”的情况,引擎将在后台建立一个helper计数变量,这个变量的名字是在原来的均值变量名后面加上一个“_COUNT”后缀。
Calculation Lowest and Highest
对于每一个数据源记录来说,如果你想在一系列从赋值表达式中获得得最大或最小的value,你就需要选择这种类型的计算。
Calculation StandardDeviation(标准偏差) and Variance(方差)
在一些特殊的报表中,你可能会需要执行一些高级的数字运算,而JasperReport已经内置了对的一些经过变量表达式赋值所得到的value的标准偏差和方差进行计算的算法。和前面计算均值的方法一样,报表引擎首先建立一些helper变量来获得相应于当前一系列值的计数和累加和,这些变量命名方式和上面一样,这里不再赘述。
Calculation System
这种类型的计算被用在当你不希望报表引擎干预你的变量运算的时候,这意味着你将自己计算变量的值。对于这种类型的计算,报表引擎唯一可以做的就是从数据源的一个迭代到另一个迭代的过程中将你已经计算好的value保存起来(conserve)。
例子:下面是一个是变量声明的简单例子,这个变量将为所有名为“Quantity”的数字型报表字段求和。
$F{Quantity}
如果我们想求得每一页的这个字段的总合,则应该如下定义:
calculation="Sum">
$F{Quantity}
new Double(0)
在上面的例子中,我们的页累加变量将会在每一新页的开始时被置为0。
5.6.2 内置的报表变量(Build-in Report Variables
JasperReport提供了一些内置的系统变量可以直接用于表达式中:
Variable PAGE_NUMBER
这个变量保存当前的页号,在报表装填结束的时候,这个变量就保存着最终文档的总页数。所以要在JasperReport的文本字段中显示页号和总页数你都可以用它。
Variable COLUMN_NUMBER
这个变量将记录当前的列号。
Variable REPORT_COUNT
当数据源迭代结束之后,这个变量里将包含被处理的数据record的总数。
Variable PAGE_COUNT
这个变量纪录当前页中处理的record的数目。
Variable COLUMN_COUNT
这个变量纪录生成当前列时所处理的record的数目。
Variable GroupName_COUNT
当我们声明一个group时,引擎将会自动建立一个用户计算构成当前group的记录数的计数变量,即在组和组的rupture之间所处理的纪录的数目。(注意,这里的GroupName是泛指组名,即任意一个组的名字)


 

至此,JasperReport的大致功能选项就都介绍完了,余下的部分如报表的各个组成部分,Scriptlet,报表元素(文本,图形元素--线,矩形,图片等),要么在JasperReport所给例子中才能有更好的理解,要么你只要用一下IReport就一目了然了(比如报表的各个组成部分在IReport中都是可视化的,文本,图形元素也都是可拖拽到报表上的,非常容易弄懂),至于高级部分SubReport的用法,这片文档也说得比较少,如果你需要的话就看看IReport的文档吧。不过我还是在下面列出了所有的英文原文,共有兴趣的朋友或我自己在遇到某些细节的时候备用。 J
6 Report Sections
When building a report design we need to define the content and the layout of its sections. The entire
structure of the report design is based on the following sections: </span> <span style="FONT-SIZE: 10pt">, </span> <span style="FONT-SIZE: 9pt"><pageHeader></span> <span style="FONT-SIZE: 10pt">,</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><columnHeader></span> <span style="FONT-SIZE: 10pt">, </span> <span style="FONT-SIZE: 9pt"><groupHeader></span> <span style="FONT-SIZE: 10pt">, </span> <span style="FONT-SIZE: 9pt"><detail></span> <span style="FONT-SIZE: 10pt">, </span> <span style="FONT-SIZE: 9pt"><groupFooter></span> <span style="FONT-SIZE: 10pt">, </span> <span style="FONT-SIZE: 9pt"><columnFoter></span> <span style="FONT-SIZE: 10pt">,</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><pageFooter></span> <span style="FONT-SIZE: 10pt">, </span> <span style="FONT-SIZE: 9pt"><summary></span> <span style="FONT-SIZE: 10pt">.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Sections are portions of the report template that have a specified height and width and can contain</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">report elements like lines, rectangles, images or text fields. Those sections are filled repeatedly at report</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">generating time and make up the final document that is being produced. When declaring the content</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">and layout of a report section, in an XML report design, we use the generic element </span> <span style="FONT-SIZE: 9pt"><band></span> <span style="FONT-SIZE: 10pt">.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">XML Syntax</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT band (printWhenExpression?, (line | rectangle | image | staticText</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">| textField | subreport | elementGroup)*)></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ATTLIST band</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">height NMTOKEN "0"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">> </span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT printWhenExpression (#PCDATA)></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Report sections are sometimes referred as report bands and represent a feature that almost all report</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">tools have and use in the same way.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Band Height</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The attribute height available in a report band declaration specifies the height in pixels for that</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">particular band and is very important in the overall report design.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The elements contained by a certain report band should always fit the band's dimensions, to avoid</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">potential bad results when generating the reports. The engine issues a warning if it finds elements</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">outside the band borders, when compiling report designs.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Skipping Bands</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">All the report sections allow you to define a report expression that will be evaluated at runtime in order</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">to decide if that particular section should be generated or skipped, when producing the document.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">This expression is introduced by the </span> <span style="FONT-SIZE: 9pt"><printWhenExpression> </span> <span style="FONT-SIZE: 10pt">that is available in any </span> <span style="FONT-SIZE: 9pt"><band></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">element of the XML report design and should always return a </span> <span style="FONT-SIZE: 9pt">java.lang.Boolean </span> <span style="FONT-SIZE: 10pt">object or </span> <span style="FONT-SIZE: 9pt">null</span> <span style="FONT-SIZE: 10pt">.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt; COLOR: #c1c1c1">The JasperReports Ultimate Guide</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Page 39</span> </div> <div style="TEXT-INDENT: 32.15pt"> <strong><font size="5"><span>6.1 Main Report Sections</span></font></strong> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">A minimal report design can contain no report section at all, because each one of them is optional. But</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">such a minimal report design won't produce very interesting documents.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">XML Syntax</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT title (band?)></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT pageHeader (band?)></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT columnHeader (band?)></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT detail (band?)></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT columnFooter (band?)></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT pageFooter (band?)></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT summary (band?)></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">So let's take a closer look at each report section and see how it behaves.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Title</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">This is the first section of the report. It is generated only once during the report filling process and</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">makes it for the beginning of the resulting document.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Being the first section of the report means that it will precede even the page header section. Those who</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">want to have the page header printed somehow before the title section will have to copy the elements</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">present on the page header also at the beginning of the title section. They could suppress the actual</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">page header on the first page using the </span> <span style="FONT-SIZE: 9pt"><printWhenExpression>, </span> <span style="FONT-SIZE: 10pt">based on the </span> <span style="FONT-SIZE: 9pt">PAGE_NUMBER</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">report variable.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">As we have already seen in the </span> <em><span style="FONT-SIZE: 10pt">4.3 Report Properties </span></em> <span style="FONT-SIZE: 10pt">paragraph, the title section could be followed by</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">a page break, if the attribute </span> <span style="FONT-SIZE: 9pt">isTitleNewPage </span> <span style="FONT-SIZE: 10pt">is set to </span> <span style="FONT-SIZE: 9pt">"true"</span> <span style="FONT-SIZE: 10pt">.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Page Header</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">This section appears at the top of each page in the generated document.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Column Header</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">This section appears at the top of each column in the generated document.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Detail</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">For each record in the data source, the engine will try to generate this section.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Column Footer</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">This section appears at the bottom of each column in the generated document. It never stretches</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">downward to acquire the content of its containing text fields and will always remain of declared fixed</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">height.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt; COLOR: #c1c1c1">The JasperReports Ultimate Guide</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Page 40</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Page Footer</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">This section appears at the bottom of each page in the generated document. Just like the column footer</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">section above, the page footer never stretches downwards to acquire the content of its containing text</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">fields and will always remain of declared fixed height.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Summary</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">This section is generated only once per report and appears at the end of the generated document, but is</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">not necessarily the last section being generated.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">That's because in some cases, the column footer or/and page footer of the last page can follow it.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">As mentioned in the </span> <em><span style="FONT-SIZE: 10pt">4.3 Report Properties </span></em> <span style="FONT-SIZE: 10pt">paragraph, the summary section can start a new page of its</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">own, by setting the </span> <span style="FONT-SIZE: 9pt">isSummaryNewPage </span> <span style="FONT-SIZE: 10pt">attribute to </span> <span style="FONT-SIZE: 9pt">"true"</span> <span style="FONT-SIZE: 10pt">. Even if this attribute remains </span> <span style="FONT-SIZE: 9pt">false</span> <span style="FONT-SIZE: 10pt">, the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">summary section always starts a new page if it does not fit on the remaining space of the last page or if</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">the report has more than one column and on the last page it has already started a second column.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">If the main report sections that we have seen here are not sufficient for what you need, maybe you</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">should consider introducing supplementary sections like group headers and group footers.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">We are now going to see how to group data on the report.</span> </div> <div style="TEXT-INDENT: 32.15pt"> <strong><font size="5"><span>6.2 Data Grouping</span></font></strong> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Groups represent a flexible way to organize data on a report. A report group is represented by sequence</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">of consecutive records in the data source that have something in common, like the value of a certain</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">report field for example.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">A report group has 3 components:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <span style="FONT-SIZE: 10pt">group expression;</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <span style="FONT-SIZE: 10pt">group header section;</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <span style="FONT-SIZE: 10pt">group footer section.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The value of the associated group expression is what makes group records stick tighter. This value is</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">the thing that they have in common. When the value of the group expression changes during the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">iteration through the data source at report filling time, a group rupture occurs and the corresponding</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">group sections </span> <span style="FONT-SIZE: 9pt"><groupFooter> </span> <span style="FONT-SIZE: 10pt">and </span> <span style="FONT-SIZE: 9pt"><groupHeader> </span> <span style="FONT-SIZE: 10pt">are inserted in the resulting document.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">We can have as many groups as we want on a report. The order of groups declared in a report design is</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">important because groups contain each other. One group contains the following group and so on. And</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">when a larger group encounters a rupture, all subsequent groups are reinitialized.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Data grouping works as expected only when the records in the data source are already</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">ordered accordingly to the group expressions used in the report.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">For example, if you want to group some products by country and city of the manufacturer,</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">the engine expects to find the records in the data source already ordered by country and city.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">If not, you should expect to find records belonging to a specific country or city in different</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">parts of the resulting document, because JasperReports does not sort the data source for you,</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">before using it.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt; COLOR: #c1c1c1">The JasperReports Ultimate Guide</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Page 41</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">XML Syntax</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT group (groupExpression?, groupHeader?, groupFooter?)></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ATTLIST group</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">name NMTOKEN #REQUIRED</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">isStartNewColumn (true | false) "false"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">isStartNewPage (true | false) "false"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">isResetPageNumber (true | false) "false"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">isReprintHeaderOnEachPage (true | false) "false"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">minHeightToStartNewPage NMTOKEN "0"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">> </span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT groupExpression (#PCDATA)></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT groupHeader (band?)></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT groupFooter (band?)></span> </div> <div style="TEXT-INDENT: 32.15pt"> <strong><font size="4"><span>Group Name</span></font></strong> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The name unequivocally identifies the group and can be used in other XML attributes, when you want</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">to refer a particular report group. The name of a group is mandatory and obeys the same naming</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">convention that we mentioned for the report parameters, fields and report variables.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Starting New Page/Column When Group Breaks</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Sometimes is useful to introduce a page or column break when a new group starts, probably because</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">that particular group is more important and should start on a page or column of its own.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">To instruct the engine to start a new page or column for a certain group, instead of going to print it on</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">the remaining space at the bottom of the page or column, you have to set to </span> <span style="FONT-SIZE: 9pt">"true" </span> <span style="FONT-SIZE: 10pt">either the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">isStartNewPage </span> <span style="FONT-SIZE: 10pt">or </span> <span style="FONT-SIZE: 9pt">isStartNewColumn </span> <span style="FONT-SIZE: 10pt">attribute.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Those two attributes are the only settings in the entire library that let you voluntary</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">introduce page breaks. In all other situation, the reporting engine introduces page breaks</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">automatically, if it needs to.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">However, in some report designs, you probably want to introduce page breaks on purpose,</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">because some particular report section of yours is larger than one page. You can achieve that</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">by introducing special dummy groups as you can see in the </span> <em><span style="FONT-SIZE: 10pt">Tips & Tricks </span></em> <span style="FONT-SIZE: 10pt">section of the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">freely available documentation, published on the </span> <em><span style="FONT-SIZE: 10pt">JasperReports site</span></em> <span style="FONT-SIZE: 10pt">.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">However, if you don't want to consistently introduce page or column breaks for a particular group, but</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">you rather do that only if the remaining space at the bottom of the page or column is too small, you</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">should consider using the </span> <span style="FONT-SIZE: 9pt">minHeightToStartNewPage </span> <span style="FONT-SIZE: 10pt">attribute.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">This attribute specifies the minimum amount of remaining vertical space required so that the group</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">does not start a new page of its own. It is measured in pixels.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Resetting Page Number</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">If required, report groups have the power to reset the built-in report variable which contains the current</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">page number (variable </span> <span style="FONT-SIZE: 9pt">PAGE_NUMBER</span> <span style="FONT-SIZE: 10pt">). This could be achieved by setting the </span> <span style="FONT-SIZE: 9pt">isResetPageNumber</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">attribute to </span> <span style="FONT-SIZE: 9pt">"true"</span> <span style="FONT-SIZE: 10pt">.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt; COLOR: #c1c1c1">The JasperReports Ultimate Guide</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Page 42</span> </div> <div style="TEXT-INDENT: 32.15pt"> <strong><font size="4"><span>Group Header</span></font></strong> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">This section is the one that marks the start of a new group in the resulting document, and it is inserted</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">in the document every time the value of the group expression changes during the iteration through the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">data source.</span> </div> <div style="TEXT-INDENT: 32.15pt"> <strong><font size="4"><span>Group Footer</span></font></strong> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Every time a report group changes, the engine adds the corresponding group footer section before</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">starting the new group or when the report ends.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Check the provided samples like </span> <em><span style="FONT-SIZE: 10pt">jasper</span></em> <span style="FONT-SIZE: 10pt">, </span> <em><span style="FONT-SIZE: 10pt">datasource </span></em> <span style="FONT-SIZE: 10pt">or </span> <em><span style="FONT-SIZE: 10pt">query</span></em> <span style="FONT-SIZE: 10pt">, to see how report groups can be used.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt; COLOR: #c1c1c1">The JasperReports Ultimate Guide</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Page 43</span> </div> <div style="TEXT-INDENT: 44.15pt"> <strong><font size="6"><span>7 Scriptlets</span></font></strong> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">All the data displayed on a report comes from the report parameters and from the report fields. This</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">data can be processed using the report variables and their expressions.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">There are specific moments in time when variable processing occurs. Some variables are initialized</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">according to their reset type when the report starts, or when a page or column break</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">is encountered, or</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">when a group changes. Furthermore, variables are evaluated every time new data is fetched from the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">data source (for every row).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">But only simple variable expressions cannot always implement complex functionality. This is where</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">scriptlets intervene. Scriptlets are sequences of Java code that are executed every time a report event</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">occurs. Through scriptlets, users have the possibility to affect the values stored by the report variables.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Since scriptlets work mainly with report variables, is important to h</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">have full control over the exact</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">moment the scriptlet is executed.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">JasperReports allows the execution of custom Java code BEFORE or AFTER it initializes the report</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">variables according to their reset type: </span> <span style="FONT-SIZE: 9pt">Report</span> <span style="FONT-SIZE: 10pt">, </span> <span style="FONT-SIZE: 9pt">Page</span> <span style="FONT-SIZE: 10pt">, </span> <span style="FONT-SIZE: 9pt">Column </span> <span style="FONT-SIZE: 10pt">or </span> <span style="FONT-SIZE: 9pt">Group</span> <span style="FONT-SIZE: 10pt">.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">In order to make use of this functionality, users only have to create a scriptlet class by extending one of</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">the following two classes:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">dori.jasper.engine.JRAbstractScriptlet</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">dori.jasper.engine.JRDefaultScriptlet</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The complete name of this custom scriptlet class (including the package) has to be specified in the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">scriptletClass </span> <span style="FONT-SIZE: 10pt">attribute of the </span> <span style="FONT-SIZE: 9pt"><jasperReport> </span> <span style="FONT-SIZE: 10pt">element and has to be available in the classpath,</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">at report filling time, so that the engine could instantiate it on the fly. If no value is specified for the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">scriptletClass </span> <span style="FONT-SIZE: 10pt">attribute, the engine will instantiate the </span> <span style="FONT-SIZE: 9pt">JRDefaultScriptlet </span> <span style="FONT-SIZE: 10pt">class.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">When creating a JasperReports scriptlet class, there are several methods that developers should</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">implement or override, like: </span> <span style="FONT-SIZE: 9pt">beforeReportInit()</span> <span style="FONT-SIZE: 10pt">, </span> <span style="FONT-SIZE: 9pt">afterReportInit()</span> <span style="FONT-SIZE: 10pt">, </span> <span style="FONT-SIZE: 9pt">beforePageInit()</span> <span style="FONT-SIZE: 10pt">,</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">afterPageInit()</span> <span style="FONT-SIZE: 10pt">, </span> <span style="FONT-SIZE: 9pt">beforeGroupInit()</span> <span style="FONT-SIZE: 10pt">, </span> <span style="FONT-SIZE: 9pt">afterGroupInit()</span> <span style="FONT-SIZE: 10pt">, etc. Those methods will be called</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">by the report engine at the appropriate time, when filling the report.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">For more complex reports, if you need to use very complicate report expressions, for grouping or</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">displaying data, maybe you should consider transferring this complexity to a separate class to which</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">you then make calls from simplified report expressions. The scriptlet class is perfect for transferring</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">this complexity to. This is because the reporting engine supplies you with a reference to the scriptlet</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">object it creates on the fly using the </span> <span style="FONT-SIZE: 9pt">REPORT_SCRIPTLET </span> <span style="FONT-SIZE: 10pt">built-in parameter.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Check the </span> <em><span style="FONT-SIZE: 10pt">scriptlet </span></em> <span style="FONT-SIZE: 10pt">sample to see this type of functionality used.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt; COLOR: #c1c1c1">The JasperReports Ultimate Guide</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Page 44</span> </div> <div style="TEXT-INDENT: 44.15pt"> <strong><font size="6"><span>8 Report Elements</span></font></strong> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The generated reports would be empty if you would not put some report elements in the report design.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The report elements are displayable objects like static texts, text fields, images, lines or rectangles, that</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">you put in your report design sections so that they appear in the final document.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">As you can see, the report elements come in two flavors:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">Text elements</span></em> <span style="FONT-SIZE: 10pt">: static texts and text fields that display dynamic content;</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">Graphic elements</span></em> <span style="FONT-SIZE: 10pt">: lines, rectangles and images.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">We shall see those two element categories and their particularities in the following sections. For now</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">we are going to present in detail the element properties that both categories share.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">When you add a report element to one of your report sections, you have to specify the relative position</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">of this element in that particular section and its size, along with other general report element properties</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">like color, transparency, stretch behavior, etc.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The properties that are common to all types of report elements are grouped in the </span> <span style="FONT-SIZE: 9pt"><reportElement></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">tag that can appear in the declaration of all report elements.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">XML Syntax</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT reportElement (printWhenExpression?)></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ATTLIST reportElement</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">positionType (Float | FixRelativeToTop | FixRelativeToBottom)</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">"FixRelativeToTop"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">isPrintRepeatedValues (true | false) "true"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">mode (Opaque | Transparent) #IMPLIED</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">x NMTOKEN #REQUIRED</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">y NMTOKEN #REQUIRED</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">width NMTOKEN #REQUIRED</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">height NMTOKEN #REQUIRED</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">isRemoveLineWhenBlank (true | false) "false"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">isPrintInFirstWholeBand (true | false) "false"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">isPrintWhenDetailOverflows (true | false) "false"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">printWhenGroupChanges CDATA #IMPLIED</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">forecolor CDATA #IMPLIED</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">backcolor CDATA #IMPLIED</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">> </span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT printWhenExpression (#PCDATA)></span> </div> <div style="TEXT-INDENT: 32.15pt"> <strong><font size="4"><span>Absolute Position</span></font></strong> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The </span> <span style="FONT-SIZE: 9pt">x </span> <span style="FONT-SIZE: 10pt">and </span> <span style="FONT-SIZE: 9pt">y </span> <span style="FONT-SIZE: 10pt">attributes of any report element are mandatory and represent x and y coordinates,</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">measured in pixels, that mark the absolute position of the top-left corner of the specified element within</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">its parent report section.</span> </div> <div style="TEXT-INDENT: 32.15pt"> <strong><font size="4"><span>Relative Position</span></font></strong> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Some report elements such as the text fields have special properties that allow them to stretch</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">downwards in order to acquire all the information they have to display. Their height is calculated at</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">runtime and may affect the other neighboring elements present in the same report section, especially</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">those placed immediately below them.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The </span> <span style="FONT-SIZE: 9pt">positionType </span> <span style="FONT-SIZE: 10pt">attribute specifies the behavior that the report element should have if the layout of</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">the report section in which it is been place is affected by stretch.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt; COLOR: #c1c1c1">The JasperReports Ultimate Guide</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Page 45</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">There are 3 possible values for the </span> <span style="FONT-SIZE: 9pt">positionType </span> <span style="FONT-SIZE: 10pt">attribute:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">Floating position</span></em> <span style="FONT-SIZE: 10pt">: The element will float in its parent section if it is pushed downwards by other</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">elements fount above it. It will try to conserve the distance between it and the neighboring</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">elements placed immediately above (</span> <span style="FONT-SIZE: 9pt">positionType="Float"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">Fixed position relative to the top of the parent band</span></em> <span style="FONT-SIZE: 10pt">: The current report element will simply ignore</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">what happens to the other section elements and tries to conserve the y offset measured from the top</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">of its parent report section (</span> <span style="FONT-SIZE: 9pt">positionType="FixRelativeToTop"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">Fixed position relative to the bottom of the parent band</span></em> <span style="FONT-SIZE: 10pt">: If the height of the parent report section is</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">affected by elements that stretch, the current element will try to conserve the original distance</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">between its bottom margin and the bottom of the band</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">(</span> <span style="FONT-SIZE: 9pt">positionType="FixRelativeToBottom"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">A report element called </span> <span style="FONT-SIZE: 9pt">e2 </span> <span style="FONT-SIZE: 10pt">will float when another report element called </span> <span style="FONT-SIZE: 9pt">e1 </span> <span style="FONT-SIZE: 10pt">stretches, only</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">if these three conditions are met:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">_ </span> <span style="FONT-SIZE: 9pt">e2 </span> <span style="FONT-SIZE: 10pt">has </span> <span style="FONT-SIZE: 9pt">postitionType="Float"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">_ </span> <span style="FONT-SIZE: 9pt">e1.y + e1.height < e2.y</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">_ </span> <span style="FONT-SIZE: 9pt">e1.width + e2.width >= max(e1.x + e1.width, e2.x + e2.width) –</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">min(e1.x, e2.x)</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The second and the third conditions together say that the element </span> <span style="FONT-SIZE: 9pt">e2 </span> <span style="FONT-SIZE: 10pt">must be placed below</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">the </span> <span style="FONT-SIZE: 9pt">e1</span> <span style="FONT-SIZE: 10pt">.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">By default, all elements have a fixed position relative to the top of the band.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">To see how element stretching and element floating work together, check the </span> <em><span style="FONT-SIZE: 10pt">stretch </span></em> <span style="FONT-SIZE: 10pt">sample provided.</span> </div> <div style="TEXT-INDENT: 32.15pt"> <strong><font size="4"><span>Element Size</span></font></strong> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The </span> <span style="FONT-SIZE: 9pt">width </span> <span style="FONT-SIZE: 10pt">and </span> <span style="FONT-SIZE: 9pt">height </span> <span style="FONT-SIZE: 10pt">attributes are mandatory and represent the size of the report element measured</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">in pixels. Additional element settings that have to do with the element stretching mechanism will</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">determine the reporting engine to sometimes ignore the specified element height. But this attribute</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">remains mandatory since even when the height is calculated dynamically, the element will not be</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">smaller than the original specified height.</span> </div> <div style="TEXT-INDENT: 32.15pt"> <strong><font size="4"><span>Element Color</span></font></strong> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">There are two attributes that represent colors: </span> <span style="FONT-SIZE: 9pt">forecolor </span> <span style="FONT-SIZE: 10pt">and </span> <span style="FONT-SIZE: 9pt">backcolor</span> <span style="FONT-SIZE: 10pt">. The fore color is the one</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">used to draw the text of the text elements and the border of the graphic elements. The back color is the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">one used to fill the background of the specified report element, if it is not transparent.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">You could specify colors using the decimal or hexadecimal representation of the integer number</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">corresponding to the desired color. The preferred way to specify colors in XML is using the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">hexadecimal representation, because it allows controlling the level for each base color of the RGB</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">system.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">For example, you can display some text in red if you set the </span> <span style="FONT-SIZE: 9pt">forecolor </span> <span style="FONT-SIZE: 10pt">attribute of the corresponding</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">text field like this:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">forecolor="#FF0000"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The equivalent using the decimal representation would be:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">forecolor="16711680"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">but the inconvenience is evident.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt; COLOR: #c1c1c1">The JasperReports Ultimate Guide</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Page 46</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The default fore color is black and the default back color is white.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Element Transparency</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Report elements can be either transparent or opaque, depending on the value you specify for the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">attribute </span> <span style="FONT-SIZE: 9pt">mode</span> <span style="FONT-SIZE: 10pt">.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The default value for this attribute depends on the type of the report element. Graphic elements like</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">rectangles and lines are opaque by default, but the images are transparent. Both static texts and text</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">fields are transparent by default, and so are the subreport elements.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Skipping Element Display</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The engine can decide at runtime if it really should display a report element, if you use the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><printWhenExpression> </span> <span style="FONT-SIZE: 10pt">that is available for all types of report elements.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">If present, this report expression should return a </span> <span style="FONT-SIZE: 9pt">java.lang.Boolean </span> <span style="FONT-SIZE: 10pt">object or </span> <span style="FONT-SIZE: 9pt">null </span> <span style="FONT-SIZE: 10pt">and is evaluated</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">every time the section containing the current element is being generated, to see if this particular</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">element should appear or not in the report.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">If the expression returns </span> <span style="FONT-SIZE: 9pt">null</span> <span style="FONT-SIZE: 10pt">, it is equivalent to returning </span> <span style="FONT-SIZE: 9pt">java.lang.Boolean.FALSE </span> <span style="FONT-SIZE: 10pt">and if the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">expression is missing, the report element will get printed every time, that is if other setting do not</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">intervene, as we shall see below.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Reprinting Elements on Section Overflows</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">When generating a report section, the engine might be forced to start a new page or column, because</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">the remaining space at the bottom of the current page or column was not sufficient for all the section</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">elements to fit in, probably because some elements have stretched.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">In such cases, you might want to reprint some of your already displayed elements, on the new page or</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">column, to recreate the context in which the page/column break occurred.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">To achieve this, you have to set </span> <span style="FONT-SIZE: 9pt">isPrintWhenDetailOverflows="true" </span> <span style="FONT-SIZE: 10pt">for all those report</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">elements you want to reappear on the next page or column.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Suppressing Repeating Values Display</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">First, let's see what exactly a "repeating value" is.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">It very much depends on the type of the report element we are talking about.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">For text field elements, this is very intuitive. In the following list containing person names taken from</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">an usual phone book, you can see that for some consecutive lines, the value of the "Family Name"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">column repeats itself (those are only dummy phone numbers </span> <em><span style="FONT-SIZE: 10pt">_</span></em> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Family Name First Name Phone</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Johnson Adam 256.12.35</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Johnson Christine 589.54.52</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Johnson Peter 546.85.95</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Johnson Richard 125.49.56</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Smith John 469.85.45</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Smith Laura 459.86.54</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Smith Denise 884.51.25</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">You might want to suppress the repeating "Family Name" values and print something like this:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt; COLOR: #c1c1c1">The JasperReports Ultimate Guide</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Page 47</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Family Name First Name Phone</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Johnson Adam 256.12.35</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Christine 589.54.52</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Peter 546.85.95</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Richard 125.49.56</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Smith John 469.85.45</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Laura 459.86.54</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Denise 884.51.25</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">You can do that, if for the text field that displays the family name, you set:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">isPrintRepeatedValues="false"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The static text elements behave in the same way. As you would expect, their value always repeats and</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">in fact it never changes, until the end of the report. This is why we call them static texts. So, if you set</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">isPrintRepeatedValues="false" </span> <span style="FONT-SIZE: 10pt">for one of your </span> <span style="FONT-SIZE: 9pt"><staticText> </span> <span style="FONT-SIZE: 10pt">elements, you should expect to</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">see it displayed only once, the first time, at the beginning of the report, and never again.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Now, what about graphic elements?</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">An image is considered to be repeating itself if its bytes are exactly the same from one occurrence to</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">the next. This could only happen if you choose to cache your images using the </span> <span style="FONT-SIZE: 9pt">isUsingCache</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">attribute available in the </span> <span style="FONT-SIZE: 9pt"><image> </span> <span style="FONT-SIZE: 10pt">element and if the corresponding </span> <span style="FONT-SIZE: 9pt"><imageExpression> </span> <span style="FONT-SIZE: 10pt">returns the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">same value from one iteration to the next (the same file name, the same URL, etc).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Lines and rectangles are always repeating themselves, because they are static elements, just like the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">static texts we have seen above. So, when deciding to not display repeating values for a line or a</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">rectangle, you should expect to see it displayed only once, at the beginning of the report and then</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">ignored until the end of the report.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The </span> <span style="FONT-SIZE: 9pt">isPrintRepeatedValues </span> <span style="FONT-SIZE: 10pt">attribute works only if the corresponding</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><printWhenExpression> </span> <span style="FONT-SIZE: 10pt">is missing. If this is not missing, it will always dictate if the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">element should be printed or not, regardless of the repeating values.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">If you decide to not display the repeating values for some of your report elements, you have the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">possibility to soften or refine this behavior, by indicating the exceptional occasions to which you might</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">want to have a particular value redisplayed, during the report generation process.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">When the repeating value spans on multiple pages or columns, you have the possibility to redisplay this</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">repeating value at least once for every page or column.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">By setting </span> <span style="FONT-SIZE: 9pt">isPrintInFirstWholeBand="true"</span> <span style="FONT-SIZE: 10pt">, you make sure that the report element will</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">reappear in the first band of a new page or column that is not an overflow from a previous page or</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">column.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Also, if the repeating value you have suppressed spans on multiple groups, you have the possibility to</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">make it reappearing at the beginning of a certain report group, is you specify the name of that particular</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">group in the </span> <span style="FONT-SIZE: 9pt">printWhenGroupChanges </span> <span style="FONT-SIZE: 10pt">attribute.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Removing Blank Space</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">When report elements are not displayed for some reason: </span> <span style="FONT-SIZE: 9pt"><printWhenExpression> </span> <span style="FONT-SIZE: 10pt">evaluated to</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Boolean.FALSE</span> <span style="FONT-SIZE: 10pt">, or repeated value being suppressed, a blank space remains where that report element</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">would have stood.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">This blank space also appears if a text field displays only blank characters or an empty text.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">There is a way to eliminate this unwanted blank space, on the vertical axis, only if some conditions are</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">met.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt; COLOR: #c1c1c1">The JasperReports Ultimate Guide</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Page 48</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">For example, if you have three successive text fields, one on top of the other like this:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">TextField1</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">TextField2</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">TextField3</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">If the second one has an empty string as its value, or contains a repeated value that you chose to</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">suppress, the output would look like this:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">TextField1</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">TextField3</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">In order to eliminate the gap between the first text field and the third, you have to set</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">isRemoveLineWhenBlank="true" </span> <span style="FONT-SIZE: 10pt">for your second text field. You would obtain something like this:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">TextField1</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">TextField3</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">But there are certain conditions that have to be met in order for this functionality to work. The blank</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">space will not be removed, if your second text field shares some vertical space with other report</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">elements that are printed even this second text fields of your does not print.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">For example, you might have some vertical lines on the sides of your report section like this:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">| TextField1 |</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">| |</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">| TextField3 |</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">or you might have a rectangle that draws a box around your text fields:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">------------------</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">| TextField1 |</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">| |</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">| TextField3 |</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">------------------</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">or even other text elements that are placed on the same horizontal with your second text field:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Label1 TextField1</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Label2</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Label3 TextField3</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">In all those situations, the blank space between the first and the third text field cannot be remove,</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">because it is being used by other report elements that are printed as you can see.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The blank vertical space between elements can be removed using the </span> <span style="FONT-SIZE: 9pt">isRemoveWhenBlank</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">attribute, only if it is not used by other elements, as explained above.</span> </div> <div style="TEXT-INDENT: 32.15pt"> <strong><font size="5"><span>8.1 Text Elements</span></font></strong> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">There are two kinds of text elements in JasperReports: static texts and text fields.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">As their names suggest it, the first are text elements with a fixed, static content, who does not change</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">during the report filling process and are used especially for introducing labels on the final document.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Text fields however, have an associated expression, which is evaluated at runtime to produce the text</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">content that will be displayed.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Both types of text elements share some properties and those are introduced using a </span> <span style="FONT-SIZE: 9pt"><textElement></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">element. We are now going to see them in detail.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt; COLOR: #c1c1c1">The JasperReports Ultimate Guide</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Page 49</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">XML Syntax</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT textElement (font?)></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ATTLIST textElement</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">textAlignment (Left | Center | Right | Justified) "Left"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">lineSpacing (Single | 1_1_2 | Double) "Single"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">> </span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Text Alignment</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">You can specify how the content of a text element should be aligned using the </span> <span style="FONT-SIZE: 9pt">textAlignment</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">attribute and choosing one of the 4 possible values: </span> <span style="FONT-SIZE: 9pt">"Left"</span> <span style="FONT-SIZE: 10pt">, </span> <span style="FONT-SIZE: 9pt">"Center"</span> <span style="FONT-SIZE: 10pt">, </span> <span style="FONT-SIZE: 9pt">"Right" </span> <span style="FONT-SIZE: 10pt">or </span> <span style="FONT-SIZE: 9pt">"Justified".</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Text Line Spacing</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The amount of space between consecutive lines of text can be set using the </span> <span style="FONT-SIZE: 9pt">lineSpacing </span> <span style="FONT-SIZE: 10pt">attribute:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">Single</span></em> <span style="FONT-SIZE: 10pt">: The paragraph text advances normally using an offset equal to the text line height</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">(</span> <span style="FONT-SIZE: 9pt">lineSpacing="Single"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">1.5 Lines</span></em> <span style="FONT-SIZE: 10pt">: The offset between two consecutive text lines is of 1 ½ lines</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">(</span> <span style="FONT-SIZE: 9pt">lineSpacing="1_1_2"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">Double</span></em> <span style="FONT-SIZE: 10pt">: The space between text lines is double the height of a single text line</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">(</span> <span style="FONT-SIZE: 9pt">lineSpacing="Double"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The font settings for the text elements are also part of the </span> <span style="FONT-SIZE: 9pt"><textElement> </span> <span style="FONT-SIZE: 10pt">tag, but we are going to see</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">them in detail, in the following separate section of this book.</span> </div> <div style="TEXT-INDENT: 32.15pt"> <strong><font size="4"><span><span>8.1.1</span></span><span><span> Fonts and Unicode Support</span></span></font></strong> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Each text element present on your report can have its own font settings. Those settings can be specified</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">using the </span> <span style="FONT-SIZE: 9pt"><font> </span> <span style="FONT-SIZE: 10pt">tag available in the </span> <span style="FONT-SIZE: 9pt"><textElement> </span> <span style="FONT-SIZE: 10pt">tag.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Since most of the time, in a report design, there are only a few types of fonts used, that are shared by</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">different text elements, there's no point forcing XML report design creators to specify the same font</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">settings for each text element, over and over again. But rather they could reference a report level font</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">declaration and adjust only some of the font settings, on the spot, if a particular text element requires it.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Report Fonts</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">A report font is in fact a collection of font settings declared at report level that can be reused</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">throughout the entire report design, when setting the font properties of text elements.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt; COLOR: #c1c1c1">The JasperReports Ultimate Guide</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Page 50</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">XML Syntax</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT reportFont EMPTY></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ATTLIST reportFont</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">name NMTOKEN #REQUIRED</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">isDefault (true | false) "false"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">fontName CDATA "sansserif"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">size NMTOKEN "10"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">isBold (true | false) "false"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">isItalic (true | false) "false"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">isUnderline (true | false) "false"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">isStrikeThrough (true | false) "false"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">pdfFontName CDATA "Helvetica"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">pdfEncoding CDATA "CP1252"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">isPdfEmbedded (true | false) "false"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">> </span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Report Font Name</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The </span> <span style="FONT-SIZE: 9pt">name </span> <span style="FONT-SIZE: 10pt">attribute of a </span> <span style="FONT-SIZE: 9pt"><reportFont> </span> <span style="FONT-SIZE: 10pt">element is mandatory and must be unique, because it will be</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">used when referencing the corresponding report font throughout the report.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Default Report Font</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">You can use </span> <span style="FONT-SIZE: 9pt">isDefault="true" </span> <span style="FONT-SIZE: 10pt">for one of your report font declarations, to mark the report font that</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">you want to be used by the reporting engine as the default base font, when dealing with text elements</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">that do not reference a particular report font. This default font will also be used by the text elements</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">that do not have any font settings at all.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">All the other report font properties are the same as those for a normal </span> <span style="FONT-SIZE: 9pt"><font> </span> <span style="FONT-SIZE: 10pt">element that we are</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">going to see below.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">XML Syntax</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT font EMPTY></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ATTLIST font</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">reportFont NMTOKEN #IMPLIED</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">fontName CDATA #IMPLIED</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">size NMTOKEN #IMPLIED</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">isBold (true | false) #IMPLIED</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">isItalic (true | false) #IMPLIED</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">isUnderline (true | false) #IMPLIED</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">isStrikeThrough (true | false) #IMPLIED</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">pdfFontName CDATA #IMPLIED</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">pdfEncoding CDATA #IMPLIED</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">isPdfEmbedded (true | false) #IMPLIED</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">> </span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Referencing a Report Font</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">When introducing the font settings for a text element of your report, you have the possibility to use a</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">report font declaration as a base, for those font settings you want to obtain.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">All the attributes of the <font> element, if present, are used only to override the attributes with the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">same name that are present in the report font declaration referenced using the </span> <span style="FONT-SIZE: 9pt">reportFont </span> <span style="FONT-SIZE: 10pt">attribute.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt; COLOR: #c1c1c1">The JasperReports Ultimate Guide</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Page 51</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">For example, if we have a report font like the following:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><reportFont</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">name="Arial_Normal"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">isDefault="true"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">fontName="Arial"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">size="8"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">pdfFontName="Helvetica"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">pdfEncoding="Cp1252"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">isPdfEmbedded="false"/></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">and we want to create a text field that has basically the same font settings like those in this report font,</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">but only a greater size, the only thing we should do is to reference this report font using the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">reportFont </span> <span style="FONT-SIZE: 10pt">attribute and specify the desired font size like this:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><textElement></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><font reportFont="Arial_Normal" size="14"/></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"></textElement></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">When the </span> <span style="FONT-SIZE: 9pt">reportFont </span> <span style="FONT-SIZE: 10pt">attribute is missing, the default report font is used as base font.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Font Name</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">In Java, there are two types of fonts: physical fonts and logical fonts. Physical fonts are the actual font</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">libraries consisting of, for example, TrueType or PostScript Type 1 fonts. The physical fonts may be</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Arial, Time, Helvetica, Courier, or any number of other fonts, including international fonts.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Logical fonts are the five font types that have been recognized by the Java platform since version 1.0:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Serif, Sans-serif, Monospaced, Dialog, and DialogInput. These logical fonts are not actual font libraries</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">that are installed anywhere on your system. They are merely font-type names recognized by the Java</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">runtime, which must be mapped to some physical font that is installed on your system.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">In the </span> <span style="FONT-SIZE: 9pt">fontName </span> <span style="FONT-SIZE: 10pt">attribute of the </span> <span style="FONT-SIZE: 9pt"><font> </span> <span style="FONT-SIZE: 10pt">element or the </span> <span style="FONT-SIZE: 9pt"><reportFont> </span> <span style="FONT-SIZE: 10pt">element, you have to specify</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">the name of a physical font or the name of a logical font. You only have to make sure the font you</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">specify really exists and is available on your system.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">For more details about fonts in Java, check the Java Tutorial or the JDK documentation.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Font Size</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The font size is measured in points and can be specified using the </span> <span style="FONT-SIZE: 9pt">size </span> <span style="FONT-SIZE: 10pt">attribute.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Font Styles and Decorations</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">There are 4 boolean attributes available in the </span> <span style="FONT-SIZE: 9pt"><font> </span> <span style="FONT-SIZE: 10pt">and </span> <span style="FONT-SIZE: 9pt"><reportFont> </span> <span style="FONT-SIZE: 10pt">elements that control the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">font style and/or decoration. Those are </span> <span style="FONT-SIZE: 9pt">isBold</span> <span style="FONT-SIZE: 10pt">, </span> <span style="FONT-SIZE: 9pt">isItalic</span> <span style="FONT-SIZE: 10pt">, </span> <span style="FONT-SIZE: 9pt">isUnderline </span> <span style="FONT-SIZE: 10pt">and </span> <span style="FONT-SIZE: 9pt">isStrikeThrough</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">and their significance should be evident to anybody.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">PDF Font Name</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">When exporting reports to PDF format, the JasperReports library uses the iText library.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">As their name states it (Portable Document Format) the PDF files can be viewed on various platforms</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">and you can be sure they will always look the same. This is partially because in this format there is a</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">special way of dealing with fonts.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt; COLOR: #c1c1c1">The JasperReports Ultimate Guide</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Page 52</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">If you want to design your reports so that they eventually be exported to PDF, you have to make sure</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">you choose the appropriate PDF font settings that correspond to the Java font settings of your text</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">elements.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The iText library knows how to deal with built-in fonts and TTF files. It recognizes the following builtin</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">font names:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Courier</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Courier-Bold</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Courier-BoldOblique</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Courier-Oblique</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Helvetica</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Helvetica-Bold</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Helvetica-BoldOblique</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Helvetica-Oblique</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Symbol</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Times-Roman</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Times-Bold</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Times-BoldItalic</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Times-Italic</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">ZapfDingbats</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The iText library requires us to specify either a built-in font name from the above list, either the name</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">of a TTF file that it can locate on disk, every time we work with fonts. The font name introduced by the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">fontName </span> <span style="FONT-SIZE: 10pt">attribute previously explained is of no use when exporting to PDF. This is why we have</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">special font attributes, so that we are able to specify the font settings that the iText library expects from</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">us.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The </span> <span style="FONT-SIZE: 9pt">pdfFontName </span> <span style="FONT-SIZE: 10pt">attribute can contain the name of a PDF built-in font from the above list or the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">name of a TTF file that can be located on disk at runtime, when exporting to PDF.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">It is for the report design creator to choose the right value for the </span> <span style="FONT-SIZE: 9pt">pdfFontName </span> <span style="FONT-SIZE: 10pt">attribute</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">that would perfectly corresponds to the Java physical or logical font specified using the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">fontName </span> <span style="FONT-SIZE: 10pt">attribute. If those two fonts, one used by the Java viewers and printers and the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">other used in the PDF format, do not represent in fact the same font, or do not at least look</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">alike, you might get unexpected results when exporting to PDF format.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Additional PDF fonts can be installed on your system if you choose one of the Acrobat Reader's font</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">packs. For example, by installing the Asian font pack from Adobe on your system, you would be able</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">to use for the </span> <span style="FONT-SIZE: 9pt">pdfFontName </span> <span style="FONT-SIZE: 10pt">attribute font names like:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Language PDF Font Name</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Simplified Chinese </span> <span style="FONT-SIZE: 9pt">STSong-Light</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Traditional Chinese </span> <span style="FONT-SIZE: 9pt">MHei-Medium</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">MSung-Light</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Japanese </span> <span style="FONT-SIZE: 9pt">HeiseiKakuGo-W5</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">HeiseiMin-W3</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Korean </span> <span style="FONT-SIZE: 9pt">HYGoThic-Medium</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">HYSMyeongJo-Medium</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">For more details about how to work with fonts when generating PDF documents, check the </span> <em><span style="FONT-SIZE: 10pt">iText</span></em> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <em><span style="FONT-SIZE: 10pt">library documentation</span></em> <span style="FONT-SIZE: 10pt">.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">PDF Encoding</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">When creating reports in different languages and wanting to export them to PDF, you have to make</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">sure that you choose the appropriate character encoding type.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">For example, an encoding type widely used in Europe is </span> <span style="FONT-SIZE: 9pt">Cp1252</span> <span style="FONT-SIZE: 10pt">, also known as </span> <span style="FONT-SIZE: 9pt">LATIN1</span> <span style="FONT-SIZE: 10pt">. Other</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">possible encoding types are:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt; COLOR: #c1c1c1">The JasperReports Ultimate Guide</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Page 53</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Character Set Encoding</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Latin 2: Eastern Europe </span> <span style="FONT-SIZE: 9pt">Cp1250</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Cyrillic </span> <span style="FONT-SIZE: 9pt">Cp1251</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Greek </span> <span style="FONT-SIZE: 9pt">Cp1253</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Turkish </span> <span style="FONT-SIZE: 9pt">Cp1254</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Windows Baltic </span> <span style="FONT-SIZE: 9pt">Cp1257</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Simplified Chinese </span> <span style="FONT-SIZE: 9pt">UniGB-UCS2-H</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">UniGB-UCS2-V</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Traditional Chinese </span> <span style="FONT-SIZE: 9pt">UniCNS-UCS2-H</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">UniCNS-UCS2-V</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Japanese </span> <span style="FONT-SIZE: 9pt">UniJIS-UCS2-H</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">UniJIS-UCS2-V</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">UniJIS-UCS2-HW-H</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">UniJIS-UCS2-HW-V</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Korean </span> <span style="FONT-SIZE: 9pt">UniKS-UCS2-H</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">UniKS-UCS2-V</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">You can find more details about how to work with fonts and character encoding when generating PDF</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">documents, here, in the </span> <em><span style="FONT-SIZE: 10pt">iText library documentation</span></em> <span style="FONT-SIZE: 10pt">.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">PDF Embedded Fonts</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">If you want to use a TTF file when exporting your reports to PDF format and you want to make sure</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">everybody will be able to view it without problem, you have to make sure that at least one of the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">following conditions are met:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <span style="FONT-SIZE: 10pt">they all have that TTF font installed on their systems;</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <span style="FONT-SIZE: 10pt">you embed the font in the PDF document itself.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Its not easy to comply with the first condition and this is why the preferred way to do it is to embed the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">TTF in the generated PDF documents that you are distributing.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">You can do that by setting the </span> <span style="FONT-SIZE: 9pt">isPdfEmbedded </span> <span style="FONT-SIZE: 10pt">attribute to </span> <span style="FONT-SIZE: 9pt">"true"</span> <span style="FONT-SIZE: 10pt">.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Further details about how to embed fonts in the PDF documents you can find in the </span> <em><span style="FONT-SIZE: 10pt">iText</span></em> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <em><span style="FONT-SIZE: 10pt">documentation</span></em> <span style="FONT-SIZE: 10pt">. A very useful example you can find in the </span> <em><span style="FONT-SIZE: 10pt">unicode </span></em> <span style="FONT-SIZE: 10pt">sample provided with the project.</span> </div> <div style="TEXT-INDENT: 32.15pt"> <strong><font size="4"><span><span>8.1.2</span></span><span><span> Static Texts</span></span></font></strong> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Static texts are text elements with fixed content, which does not change during the report filling</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">process. They are used mostly to introduce static text label in the generated documents.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">XML Syntax</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT staticText (reportElement, textElement?, text?)></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT text (#PCDATA)></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">As you can see from the above presented syntax, besides element general properties and text specific</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">properties that we have already explained, a static text definition has in addition only the </span> <span style="FONT-SIZE: 9pt"><text> </span> <span style="FONT-SIZE: 10pt">tag,</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">which introduces the fixed text content of the static text element.</span> </div> <div style="TEXT-INDENT: 32.15pt"> <strong><font size="4"><span><span>8.1.3</span></span><span><span> Text Fields</span></span></font></strong> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Unlike static text elements, which do not change their text content, text fields have an associated</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">expression that is evaluated with every iteration in the data source, in order to obtain the text content</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">that has to be displayed.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt; COLOR: #c1c1c1">The JasperReports Ultimate Guide</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Page 54</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">XML Syntax</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT textField (reportElement, textElement?, textFieldExpression?,</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">anchorNameExpression?, hyperlinkReferenceExpression?,</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">hyperlinkAnchorExpression?, hyperlinkPageExpression?)></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ATTLIST textField</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">isStretchWithOverflow (true | false) "false"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">evaluationTime (Now | Report | Page | Column | Group) "Now"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">evaluationGroup CDATA #IMPLIED</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">pattern CDATA #IMPLIED</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">isBlankWhenNull (true | false) "false"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">hyperlinkType (None | Reference | LocalAnchor | LocalPage |</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">RemoteAnchor | RemotePage) "None"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">> </span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT textFieldExpression (#PCDATA)></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ATTLIST textFieldExpression</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">class (java.lang.Boolean | java.lang.Byte | java.util.Date |</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">java.sql.Timestamp | java.lang.Double | java.lang.Float | java.lang.Integer</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">| java.lang.Long | java.lang.Short | java.math.BigDecimal |</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">java.lang.String) "java.lang.String"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">> </span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Variable Height Text Fields</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Given the fact that text fields have a dynamic content, most of the time you wont be able to exactly</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">anticipate the amount of space you have to provide for your text fields so that they can display all their</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">content.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">If the space you reserve for your text fields is not sufficient, the text content will be truncated so that it</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">fits in the available area.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">This scenario is not always acceptable and you can let the reporting engine to calculate itself at runtime</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">the amount of space required to display the entire content of the text field and automatically adjust the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">size of the report element.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">You can achieve this by setting the </span> <span style="FONT-SIZE: 9pt">isStretchWithOverflow </span> <span style="FONT-SIZE: 10pt">to </span> <span style="FONT-SIZE: 9pt">"true" </span> <span style="FONT-SIZE: 10pt">for the particular text field</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">elements you are interested in. By doing this, you make sure that if the specified height for the text</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">field is not sufficient, it will automatically be increased (never decreased) in order to be able to display</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">the entire text content.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">When text fields are affected by this stretch mechanism, the entire report section to which they belong</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">to will be also stretched.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Evaluating Text Fields</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Normally, all the report expressions are evaluated immediately, using the current values of all the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">parameters, fields and variables at that particular moment. It is like making a photo of all data, for</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">every iteration in the data source, during the report filling process.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">This means that at any particular time, you won't have access to values that are going to be calculated</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">later, in the report filling process. It perfectly makes sense, since all the variables are calculated step by</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">step and reach their final value only when the iteration arrives at the end of the data source range they</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">cover.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">For example, a report variable that calculates the sum of a field for each page will not contain the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">expected sum until the end of the page is reached. That's because the sum is calculated step by step,</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt; COLOR: #c1c1c1">The JasperReports Ultimate Guide</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Page 55</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">when iterating through the data source records, and at any particular time, the sum will be only partial,</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">since not all the records of the specified range have been processed.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">If this is the case, how to display the page sum of a this field, on the page header, since this value will</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">be known only when the end of the page is reached. At the beginning of the page, when generating the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">page header, our sum variable would contain zero, or its initial value.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Fortunately, JasperReports has a very interesting feature that lets you decide the exact moment you</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">want the text field expression to be evaluated, avoiding the default behavior which makes this</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">expression be evaluated immediately, when generating the current report section.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">It is the </span> <span style="FONT-SIZE: 9pt">evaluationTime </span> <span style="FONT-SIZE: 10pt">attribute we are talking about. It can have one of the following values:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">Immediate evaluation</span></em> <span style="FONT-SIZE: 10pt">: The text field expression is evaluated when filling the current band</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">(</span> <span style="FONT-SIZE: 9pt">evaluationTime="Now"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">End of report evaluation</span></em> <span style="FONT-SIZE: 10pt">: The text field expression is evaluated when reaching the end of the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">report (</span> <span style="FONT-SIZE: 9pt">evaluationTime="Report"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">End of page evaluation</span></em> <span style="FONT-SIZE: 10pt">: The text field expression is evaluated when reaching the end of the current</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">page (</span> <span style="FONT-SIZE: 9pt">evaluationTime="Page"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">End of column evaluation</span></em> <span style="FONT-SIZE: 10pt">: The text field expression is evaluated when reaching the end of the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">current column (</span> <span style="FONT-SIZE: 9pt">evaluationTime="Column"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">End of group evaluation</span></em> <span style="FONT-SIZE: 10pt">: The text field expression is evaluated when the group specified by the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">evaluationGroup </span> <span style="FONT-SIZE: 10pt">attribute changes (</span> <span style="FONT-SIZE: 9pt">evaluationTime="Group"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The default value for this attribute is </span> <span style="FONT-SIZE: 9pt">"Now", </span> <span style="FONT-SIZE: 10pt">as already mentioned. In the example presented above,</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">you could easily specify </span> <span style="FONT-SIZE: 9pt">evaluationTime="Page" </span> <span style="FONT-SIZE: 10pt">for the text field placed in the page header</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">section, so that it displays the value of the sum variable only when reaching the end of the current page.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The only restriction you should be aware of, when deciding to avoid the immediate</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">evaluation of the text field expression, is that in such cases, the text field will never stretch</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">in order to acquire all its content.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">This is because the text element height is calculated when the report section is generated and</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">even the engine will come back later with the text content of the text field, the element</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">height will not be adapted, because it will ruin the already created layout.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Suppressing Null Values Display</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">If the text field expression returns </span> <span style="FONT-SIZE: 9pt">null</span> <span style="FONT-SIZE: 10pt">, your text field will display the "null" text in the generated</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">document. A simple way to avoid this is to set the </span> <span style="FONT-SIZE: 9pt">isBlankWhenNull </span> <span style="FONT-SIZE: 10pt">attribute to </span> <span style="FONT-SIZE: 9pt">"true"</span> <span style="FONT-SIZE: 10pt">. By doing</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">this, the text field will cease to display "null" and will display an empty string. This way nothing will</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">appear on your document if the text field value is </span> <span style="FONT-SIZE: 9pt">null</span> <span style="FONT-SIZE: 10pt">.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Formatting Output</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Of course, when dealing with numeric or date/time values, you could use the Java API to format the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">output of the text field expressions yourself. But there is a more convenient way to do it: by using the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">pattern attribute available in the </span> <span style="FONT-SIZE: 9pt"><textField> </span> <span style="FONT-SIZE: 10pt">element.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The value you should supply to this attribute is the same that you would supply if it were for you to</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">format the value using either the </span> <span style="FONT-SIZE: 9pt">java.text.DecimalFormat </span> <span style="FONT-SIZE: 10pt">class or</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">java.text.SimpleDateFormat </span> <span style="FONT-SIZE: 10pt">class, depending on the type of value to format.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">In fact, what the engine does is to instantiate the </span> <span style="FONT-SIZE: 9pt">java.text.DecimalFormat </span> <span style="FONT-SIZE: 10pt">class if the text field</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">expression returns subclasses of the </span> <span style="FONT-SIZE: 9pt">java.lang.Number </span> <span style="FONT-SIZE: 10pt">class or to instantiate the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">java.text.SimpleDataFormat </span> <span style="FONT-SIZE: 10pt">if the text field expression return </span> <span style="FONT-SIZE: 9pt">java.util.Date </span> <span style="FONT-SIZE: 10pt">or</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">java.sql.Timestamp </span> <span style="FONT-SIZE: 10pt">objects.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">For more detail about the syntax of this </span> <span style="FONT-SIZE: 9pt">pattern </span> <span style="FONT-SIZE: 10pt">attribute, check the Java API documentation for those</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">two classes: </span> <span style="FONT-SIZE: 9pt">java.text.DecimalFormat </span> <span style="FONT-SIZE: 10pt">and </span> <span style="FONT-SIZE: 9pt">java.text.SimpleDateFormat</span> <span style="FONT-SIZE: 10pt">.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt; COLOR: #c1c1c1">The JasperReports Ultimate Guide</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Page 56</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Text Field Expression</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">We have already talked about the text field expression. There is nothing more to say about it except</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">that it is introduced by the </span> <span style="FONT-SIZE: 9pt"><textFieldExpression> </span> <span style="FONT-SIZE: 10pt">element and can return values from only a</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">limited range of classes listed below:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">java.lang.Boolean</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">java.lang.Byte</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">java.util.Date</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">java.sql.Timestamp</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">java.lang.Double</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">java.lang.Float</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">java.lang.Integer</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">java.lang.Long</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">java.lang.Short</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">java.math.BigDecimal</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">java.lang.String</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">If the text field expression class is not specified using the </span> <span style="FONT-SIZE: 9pt">class </span> <span style="FONT-SIZE: 10pt">attribute, it is assumed to be</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">java.lang.String</span> <span style="FONT-SIZE: 10pt">, by default.</span> </div> <div style="TEXT-INDENT: 32.15pt"> <strong><font size="5"><span>8.2 Graphic Elements</span></font></strong> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The second major category of report elements, besides text elements that we have seen, are the graphic</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">elements. In this category we have lines, rectangles and images.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">They all have some properties in common and those are grouped under the attributes of the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><graphicElement> </span> <span style="FONT-SIZE: 10pt">tag.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">XML Syntax</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT graphicElement EMPTY></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ATTLIST graphicElement</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">stretchType (NoStretch | RelativeToTallestObject |</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">RelativeToBandHeight) "NoStretch"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">pen (None | Thin | 1Point | 2Point | 4Point | Dotted) #IMPLIED</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">fill (Solid) "Solid"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">> </span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Stretch Behavior</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The </span> <span style="FONT-SIZE: 9pt">stretchType </span> <span style="FONT-SIZE: 10pt">attribute of a graphic element can be used to customize the stretch behavior of the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">element when on the same report section there are text fields that stretch themselves because their text</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">content is too large to fit in the original text field height.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">When stretchable text fields are present on a report section, the height of the report section itself will be</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">affected be stretch.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">A graphic element can respond to the modification of the report section layout in three ways:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">Won't stretch</span></em> <span style="FONT-SIZE: 10pt">: The graphic element preserves its original specified height</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">(</span> <span style="FONT-SIZE: 9pt">strechType="NoStretch"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">Stretching relative to the parent band height</span></em> <span style="FONT-SIZE: 10pt">: The graphic element will adapt its height to match</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">the new height of the report section it placed on, which has been affected by stretch</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">(</span> <span style="FONT-SIZE: 9pt">stretchType="RelativeToBandHeight"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">Stretching relative to the tallest element in group</span></em> <span style="FONT-SIZE: 10pt">: You have the possibility to group the elements</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">of a report section in multiple imbricate groups, if you like. The only reason you might have for</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">grouping your report elements is to be able to customize their stretch behavior. Details about how</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">to group elements are supplied in the section </span> <em><span style="FONT-SIZE: 10pt">8.4 Element Groups </span></em> <span style="FONT-SIZE: 10pt">that will follow. Graphic</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt; COLOR: #c1c1c1">The JasperReports Ultimate Guide</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Page 57</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">elements can be made to automatically adapt their height to fit the amount of stretch suffered by</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">the tallest element in the group that they are part of</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">(</span> <span style="FONT-SIZE: 9pt">stretchType="RelativeToTallestObject"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Border Thickness</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Unlike text elements, the graphic elements always have a border. You can control the type and</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">thickness of it using the </span> <span style="FONT-SIZE: 9pt">pen </span> <span style="FONT-SIZE: 10pt">attribute. Remember that the color of the border comes from the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">forecolor </span> <span style="FONT-SIZE: 10pt">attribute presented when describing the </span> <span style="FONT-SIZE: 9pt"><reportElement> </span> <span style="FONT-SIZE: 10pt">tag, in a previous chapter.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Here are all the possible types for a graphic element border:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">No border</span></em> <span style="FONT-SIZE: 10pt">: The graphic element will not display any border around it (</span> <span style="FONT-SIZE: 9pt">pen="None"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">Thin border</span></em> <span style="FONT-SIZE: 10pt">: The border around the graphic element will be half a point thick (</span> <span style="FONT-SIZE: 9pt">pen="Thin"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">1 point thick border</span></em> <span style="FONT-SIZE: 10pt">: Normal border (</span> <span style="FONT-SIZE: 9pt">pen="1Point"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">2 points thick border</span></em> <span style="FONT-SIZE: 10pt">: Thick border (</span> <span style="FONT-SIZE: 9pt">pen="2Point"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">4 point thick border</span></em> <span style="FONT-SIZE: 10pt">: (</span> <span style="FONT-SIZE: 9pt">pen="4Point"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">Dotted border</span></em> <span style="FONT-SIZE: 10pt">: The border will be 1 point thick and made of dots (</span> <span style="FONT-SIZE: 9pt">pen="Dotted"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The default border around graphic elements depends on their type. Lines and rectangles have a normal</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">1 point thick border by default. Images however, do not display any border, by default.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Background Fill Style</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The </span> <span style="FONT-SIZE: 9pt">fill </span> <span style="FONT-SIZE: 10pt">attribute specifies the style of the background for the graphic elements, but the only style</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">supported for the moment is the solid fill style, which is also the default (</span> <span style="FONT-SIZE: 9pt">fill="Solid"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="TEXT-INDENT: 32.15pt"> <strong><font size="4"><span><span>8.2.1</span></span><span><span> Lines</span></span></font></strong> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">When displaying a line element, JasperReports draws one of the two diagonals of the rectangle</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">represented by the </span> <span style="FONT-SIZE: 9pt">x</span> <span style="FONT-SIZE: 10pt">, </span> <span style="FONT-SIZE: 9pt">y</span> <span style="FONT-SIZE: 10pt">, </span> <span style="FONT-SIZE: 9pt">width </span> <span style="FONT-SIZE: 10pt">and </span> <span style="FONT-SIZE: 9pt">height </span> <span style="FONT-SIZE: 10pt">attributes specified for this particular line element.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">XML Syntax</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT line (reportElement, graphicElement?)></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ATTLIST line</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">direction (TopDown | BottomUp) "TopDown"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">> </span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Line Direction</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Which one of the two diagonals of the rectangle should be drawn can be decided using the direction</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">attribute:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <span style="FONT-SIZE: 10pt">The diagonal that starts in the top-left corner of the rectangle and goes to the bottom left corner is</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">drawn in case you set </span> <span style="FONT-SIZE: 9pt">direction="TopDown"</span> <span style="FONT-SIZE: 10pt">.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <span style="FONT-SIZE: 10pt">The line will start in the bottom-left corner and will go to the upper-right if you choose</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">direction="BottomUp"</span> <span style="FONT-SIZE: 10pt">.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">You can draw vertical lines by specifying </span> <span style="FONT-SIZE: 9pt">width="0" </span> <span style="FONT-SIZE: 10pt">and horizontal lines setting </span> <span style="FONT-SIZE: 9pt">height="0"</span> <span style="FONT-SIZE: 10pt">. For</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">such lines the direction is not important.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The default direction for a line is </span> <span style="FONT-SIZE: 9pt">"TopDown"</span> <span style="FONT-SIZE: 10pt">.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt; COLOR: #c1c1c1">The JasperReports Ultimate Guide</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Page 58</span> </div> <div style="TEXT-INDENT: 32.15pt"> <strong><font size="4"><span><span>8.2.2</span></span><span><span> Rectangles</span></span></font></strong> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The rectangles are the most basic graphic elements. This is why there are no supplementary settings to</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">make for the declaration of a rectangle element, besides those already seen when talking about the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><reportElement> </span> <span style="FONT-SIZE: 10pt">and </span> <span style="FONT-SIZE: 9pt"><graphicElement> </span> <span style="FONT-SIZE: 10pt">tags.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">XML Syntax</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT rectangle (reportElement, graphicElement?)></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">For more detailed examples of lines and rectangles, check the </span> <em><span style="FONT-SIZE: 10pt">shapes </span></em> <span style="FONT-SIZE: 10pt">sample.</span> </div> <div style="TEXT-INDENT: 32.15pt"> <strong><font size="4"><span><span>8.2.3</span></span><span><span> Images</span></span></font></strong> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The most complex graphic elements that you can have on a report are the images.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Just like for the text field elements, their content is dynamically evaluated at runtime, using a report</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">expression.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">XML Syntax</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT image (reportElement, graphicElement?, imageExpression?,</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">anchorNameExpression?, hyperlinkReferenceExpression?,</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">hyperlinkAnchorExpression?, hyperlinkPageExpression?)></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ATTLIST image</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">scaleImage (Clip | FillFrame | RetainShape) "RetainShape"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">isUsingCache (true | false) "true"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">evaluationTime (Now | Report | Page | Column | Group) "Now"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">evaluationGroup CDATA #IMPLIED</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">hyperlinkType (None | Reference | LocalAnchor | LocalPage |</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">RemoteAnchor | RemotePage) "None"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">> </span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT imageExpression (#PCDATA)></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ATTLIST imageExpression</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">class (java.lang.String | java.io.File | java.net.URL |</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">java.io.InputStream | java.awt.Image) "java.lang.String"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">> </span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Scaling Images</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Given the fact that images are loaded at runtime, there is no way knowing their exact size, when</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">creating the report design. It might be that the dimensions of the image element specified at design time</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">do not correspond to the actual image loaded at runtime.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">This is why you have to decide how you expect the image to behave in order to adapt to the original</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">image element dimensions you specified in the report design. There is the </span> <span style="FONT-SIZE: 9pt">scaleImage </span> <span style="FONT-SIZE: 10pt">attribute that</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">allows you to do that, by choosing one of its 3 possible values:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">Clipping the image</span></em> <span style="FONT-SIZE: 10pt">: If the actual image is larger than the image element size, it will be cut off so</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">that it keeps its original resolution, and only the region that fits the specified size will be displayed</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">(</span> <span style="FONT-SIZE: 9pt">scaleImage="Clip"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt; COLOR: #c1c1c1">The JasperReports Ultimate Guide</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Page 59</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">Forcing the image size</span></em> <span style="FONT-SIZE: 10pt">: If the dimensions of the actual image do not fit those specified for the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">image element that displays it, the image can be forced to obey them and stretch itself so that it fits</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">in the designated output area. It will be deformed if necessary (</span> <span style="FONT-SIZE: 9pt">scaleImage="FillFrame"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">Keeping image proportions</span></em> <span style="FONT-SIZE: 10pt">: If the actual image does not fit into the image element, it can be</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">adapted to those dimensions without needing to deform it and keep its original proportions</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">(</span> <span style="FONT-SIZE: 9pt">scaleImage="RetainShape"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Retain Shape</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Clip</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Fill Frame</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">- figure 7 -</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Caching Images</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">All image elements have dynamic content. There are no special elements to introduce static images on</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">the reports, like we have special static text elements.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">However, most of the time, the images on a report are in fact static and do not necessarily come from</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">the data source or from parameters. In the majority of cases, they are loaded from files on disk and</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">represent logos and other static resources.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">If we have to display the same image multiple times on a report, if it is about a logo appearing on the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">page header for example, there is no point on loading the image file every time we have to display it.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">We can instruct the reporting engine to cache this particular image. This way we are making sure that</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">the image will be loaded from disk or from its particular location only once and then it will only be</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">reused every time it has to be displayed.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">By setting the </span> <span style="FONT-SIZE: 9pt">isUsingCache </span> <span style="FONT-SIZE: 10pt">attribute to </span> <span style="FONT-SIZE: 9pt">"true"</span> <span style="FONT-SIZE: 10pt">, the reporting engine will try to recognize</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">previously loaded images using their specified source. For example, it will recognize an image if the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">image source is a file name that it has already loaded, or if it is the same URL.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">This caching functionality is available only for image elements that have expressions returning</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">java.lang.String </span> <span style="FONT-SIZE: 10pt">objects as the image source, representing file names, URLs or classpath</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">resources. That's because the engine uses the image source string as the key to recognize that it is the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">same image that it has already cached.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Evaluating Images</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">As we have already seen when talking about text fields, you have the possibility to postpone the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">evaluation of the image expression, which by default is performed immediately.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">This would allow you to display in some region of a document, images that are going to be built or</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">chose only later in the report filling process, due to complex algorithms or whatever.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The same attributes, </span> <span style="FONT-SIZE: 9pt">evaluationTime </span> <span style="FONT-SIZE: 10pt">and </span> <span style="FONT-SIZE: 9pt">evaluationGroup, </span> <span style="FONT-SIZE: 10pt">that we have talked about in the text</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">fields section are available also in the </span> <span style="FONT-SIZE: 9pt"><image> </span> <span style="FONT-SIZE: 10pt">element. The </span> <span style="FONT-SIZE: 9pt">evaluationTime </span> <span style="FONT-SIZE: 10pt">attribute can have the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">following values:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">Immediate evaluation</span></em> <span style="FONT-SIZE: 10pt">: The image expression is evaluated when filling the current band</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">(</span> <span style="FONT-SIZE: 9pt">evaluationTime="Now"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">End of report evaluation</span></em> <span style="FONT-SIZE: 10pt">: The image expression is evaluated when reaching the end of the report</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">(</span> <span style="FONT-SIZE: 9pt">evaluationTime="Report"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">End of page evaluation</span></em> <span style="FONT-SIZE: 10pt">: The image expression is evaluated when reaching the end of the current</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">page (</span> <span style="FONT-SIZE: 9pt">evaluationTime="Page"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt; COLOR: #c1c1c1">The JasperReports Ultimate Guide</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Page 60</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">End of column evaluation</span></em> <span style="FONT-SIZE: 10pt">: The image expression is evaluated when reaching the end of the current</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">column (</span> <span style="FONT-SIZE: 9pt">evaluationTime="Column"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">End of group evaluation</span></em> <span style="FONT-SIZE: 10pt">: The image expression is evaluated when the group specified by the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">evaluationGroup </span> <span style="FONT-SIZE: 10pt">attribute changes (</span> <span style="FONT-SIZE: 9pt">evaluationTime="Group"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The default value for this attribute is </span> <span style="FONT-SIZE: 9pt">"Now"</span> <span style="FONT-SIZE: 10pt">.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Image Expression</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The value returned by the image expression is used as the source for the image that is going to be</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">displayed. The image expression is introduced by the </span> <span style="FONT-SIZE: 9pt"><imageExpression> </span> <span style="FONT-SIZE: 10pt">element and can return</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">values from only a limited range of classes listed below:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">java.lang.String</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">java.io.File</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">java.net.URL</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">java.io.InputStream</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">java.awt.Image</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">When the image expression returns a </span> <span style="FONT-SIZE: 9pt">java.lang.String </span> <span style="FONT-SIZE: 10pt">value, the engine will try to see</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">whether the value represents an URL from which to load the image. If it is not a valid URL</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">representation, it will try to locate a file on disk and load the image from it, assuming that</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">the value represents a file name. If no file is found, it will finally assume that the string</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">value represents the location of a classpath resource and will try to load the image from</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">there. Only if all those fail, an exception will be thrown.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">If the image expression class is not specified using the </span> <span style="FONT-SIZE: 9pt">class </span> <span style="FONT-SIZE: 10pt">attribute, it is assumed to be</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">java.lang.String</span> <span style="FONT-SIZE: 10pt">, by default.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The </span> <em><span style="FONT-SIZE: 10pt">images </span></em> <span style="FONT-SIZE: 10pt">sample provided with the project contains several examples of image elements.</span> </div> <div style="TEXT-INDENT: 32.15pt"> <strong><font size="4"><span><span>8.2.4</span></span><span><span> Charts and Graphics</span></span></font></strong> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The JasperReports library does not produce charts and graphics itself. This is not one of its goals.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">However, it can easily integrate charts and graphics produces by other, more specialized Java libraries.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The great majority of available Java libraries that produce charts and graphics can output to image files</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">or to in-memory Java image objects. This is why it shouldn't be hard for anybody to put a chart or a</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">graphic generated by one of those libraries into a JasperReports document using a normal image</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">element that we have presented in the previous section of this book.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">You can see this working in the sample called </span> <em><span style="FONT-SIZE: 10pt">chart</span></em> <span style="FONT-SIZE: 10pt">, which comes with the project.</span> </div> <div style="TEXT-INDENT: 32.15pt"> <strong><font size="5"><span>8.3 Hyperlinks</span></font></strong> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">JasperReports allows you to create drill-down reports, to introduce tables of contents in your</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">documents or to redirect viewers to other external documents using special report elements called</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">hyperlinks.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Hyperlinks are special elements that contain a reference to a local destination within the current</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">document or to an external resource to which the viewer of the document will be redirected if he or she</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">clicks on that particular hyperlink element.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Hyperlinks are not the only actors in this viewer-redirecting scenario. There has to be a way for you to</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">specify what are the destinations in a document. These local destinations are called anchors.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt; COLOR: #c1c1c1">The JasperReports Ultimate Guide</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Page 61</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">There are no special report elements that introduce hyperlinks or anchors in a report design, but rather</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">some special setting that make an usual report element to be a hyperlink or/and an anchor.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">In JasperReports, only text field elements and image elements can be hyperlinks or anchors. This is</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">because for both types of elements, there are special settings that allow you to specify the hyperlink</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">reference to which the hyperlink will point or the name of the local anchor. Note that a particular text</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">field or image can be both anchor and hyperlink at the same time.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">XML Syntax</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT anchorNameExpression (#PCDATA)></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT hyperlinkReferenceExpression (#PCDATA)></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT hyperlinkAnchorExpression (#PCDATA)></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT hyperlinkPageExpression (#PCDATA)></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Hyperlink Type</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">When presenting the XML syntax for text field elements and image elements, you probably saw that</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">there was an attribute called </span> <span style="FONT-SIZE: 9pt">hyperlinkType, </span> <span style="FONT-SIZE: 10pt">which we didn't explain at that moment. We are going</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">to do that right now and here are the possible values for this attribute along with their significance:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">No hyperlink</span></em> <span style="FONT-SIZE: 10pt">: By default, neither the text fields nor the images represent hyperlinks, even if the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">special hyperlink expressions are present (</span> <span style="FONT-SIZE: 9pt">hyperlinkType="None"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">External reference</span></em> <span style="FONT-SIZE: 10pt">: The current hyperlink points to an external resource specified by the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">corresponding </span> <span style="FONT-SIZE: 9pt"><hyperlinkReferenceExpression> </span> <span style="FONT-SIZE: 10pt">element, usually an URL</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">(</span> <span style="FONT-SIZE: 9pt">hyperlinkType="Reference"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">Local anchor</span></em> <span style="FONT-SIZE: 10pt">: The current hyperlink points to a local anchor specified by the corresponding</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><hyperlinkAnchorExpression> </span> <span style="FONT-SIZE: 10pt">element (</span> <span style="FONT-SIZE: 9pt">hyperlinkType="LocalAnchor"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">Local page</span></em> <span style="FONT-SIZE: 10pt">: The current hyperlink points to a 1 based page index within the current document</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">specified by the corresponding </span> <span style="FONT-SIZE: 9pt"><hyperlinkPageExpression> </span> <span style="FONT-SIZE: 10pt">element</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">(</span> <span style="FONT-SIZE: 9pt">hyperlinkType="LocalPage"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">Remote anchor</span></em> <span style="FONT-SIZE: 10pt">: The current hyperlink points to an anchor specified by the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><hyperlinkAnchorExpression> </span> <span style="FONT-SIZE: 10pt">element, within an external document indicated by the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">corresponding </span> <span style="FONT-SIZE: 9pt"><hyperlinkReferenceExpression> </span> <span style="FONT-SIZE: 10pt">element</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">(</span> <span style="FONT-SIZE: 9pt">hyperlinkType="RemoteAnchor"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <em><span style="FONT-SIZE: 10pt">Remote page</span></em> <span style="FONT-SIZE: 10pt">: The current hyperlink points to a 1 based page index specified by the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><hyperlinkPageExpression> </span> <span style="FONT-SIZE: 10pt">element, within an external document indicated by the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">corresponding </span> <span style="FONT-SIZE: 9pt"><hyperlinkReferenceExpression> </span> <span style="FONT-SIZE: 10pt">element</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">(</span> <span style="FONT-SIZE: 9pt">hyperlinkType="RemotePage"</span> <span style="FONT-SIZE: 10pt">).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Anchor Expression</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">If present in a text field or image element declaration, the </span> <span style="FONT-SIZE: 9pt"><anchorNameExpression> </span> <span style="FONT-SIZE: 10pt">tag will</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">transform that particular text field or image into a local anchor of the resulting document, to which</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">hyperlinks can point. The anchor will bare the name returned after evaluating the anchor name</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">expression, which should always return </span> <span style="FONT-SIZE: 9pt">java.lang.String </span> <span style="FONT-SIZE: 10pt">values.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Hyperlink Expressions</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Depending on the current hyperlink type, one or two of the following expressions will be evaluated and</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">used to build the reference to which the hyperlink element will point:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt; COLOR: #c1c1c1">The JasperReports Ultimate Guide</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Page 62</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><hyperlinkReferenceExpression></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><hyperlinkAnchorExpression></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><hyperlinkPageExpression</span> <span style="FONT-SIZE: 10pt">></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">What is important to know is that the first two should always return </span> <span style="FONT-SIZE: 9pt">java.lang.String </span> <span style="FONT-SIZE: 10pt">and the third</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">should return </span> <span style="FONT-SIZE: 9pt">java.lang.Integer </span> <span style="FONT-SIZE: 10pt">values.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">There is a special sample called </span> <em><span style="FONT-SIZE: 10pt">hyperlink</span></em> <span style="FONT-SIZE: 10pt">, provided with the projects, which shows how this type of</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">report elements can be used.</span> </div> <div style="TEXT-INDENT: 32.15pt"> <strong><font size="5"><span>8.4 Element Groups</span></font></strong> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Report elements placed in any report section can be arranged in multiple imbricate groups. The only</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">reason you might have for grouping your elements is to be able to customize the stretch behavior of the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">graphic elements, as explained in the section </span> <em><span style="FONT-SIZE: 10pt">8.2 Graphic Elements</span></em> <span style="FONT-SIZE: 10pt">.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The </span> <span style="FONT-SIZE: 9pt">stretchType </span> <span style="FONT-SIZE: 10pt">attribute, available for graphic elements, has among its possible values one called</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">"</span> <span style="FONT-SIZE: 9pt">RelativeToTallestObject</span> <span style="FONT-SIZE: 10pt">". When choosing this option, the engine will try to identify the object</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">from the same group with the current graphic element, which suffered the biggest amount of stretch. It</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">will then adapt the height of the current graphic element to the height of this tallest element of the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">group.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">But for this to work, you have to group your elements. This is done using the </span> <span style="FONT-SIZE: 9pt"><elementGroup> </span> <span style="FONT-SIZE: 10pt">and</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"></elementGroup> </span> <span style="FONT-SIZE: 10pt">tags to mark the elements that are part of the same group.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">XML Syntax</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT elementGroup (line | rectangle | image | staticText | textField |</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">subreport | elementGroup)*></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Element groups can contain other nested element groups and there is no limit on the number of the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">nested element groups.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Check the </span> <em><span style="FONT-SIZE: 10pt">stretch </span></em> <span style="FONT-SIZE: 10pt">sample, to see how element grouping works.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt; COLOR: #c1c1c1">The JasperReports Ultimate Guide</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Page 63</span> </div> <div style="TEXT-INDENT: 44.15pt"> <strong><font size="6"><span>9 Subreports</span></font></strong> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Subreports are an import feature for a report-generating tool. They allow the creation of more complex</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">reports and simplify the design work. The subreports are very useful when creating master-detail type</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">of reports or when the structure of a single report is not sufficient to describe the complexity of the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">desired output document.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">A subreport is in fact a normal report that is been incorporated as apart of another report. You can</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">imbricate your subreports and make a subreport that contains itself other</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">subreports, the nesting level</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">not being limited.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">On the other hand, a subreport is also a special kind of a report element that helps you introduce a</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">subreport into the parent report.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">There's nothing more to say about subreports, seen as normal reports, because they are compiled and</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">filled just like normal reports are and we already have seen all that in previous chapters. In fact, any</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">report design can be used as a subreport when incorporated into another report design, without the need</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">to change anything inside it.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">What we are going to see now, are the details concerning the </span> <span style="FONT-SIZE: 9pt"><subreport> </span> <span style="FONT-SIZE: 10pt">element that you use when</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">introducing subreports into master reports.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">XML Syntax</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT subreport (reportElement, parametersMapExpression?,</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">subreportParameter*, (connectionExpression | dataSourceExpression)?,</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">subreportExpression?)></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ATTLIST subreport</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">isUsingCache (true | false) "true"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">> </span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT parametersMapExpression (#PCDATA)></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT subreportParameter (subreportParameterExpression?)></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ATTLIST subreportParameter</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">name NMTOKEN #REQUIRED</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">> </span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT subreportParameterExpression (#PCDATA)></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT connectionExpression (#PCDATA)></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT dataSourceExpression (#PCDATA)></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ELEMENT subreportExpression (#PCDATA)></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><!ATTLIST subreportExpression</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">class (java.lang.String | java.io.File | java.net.URL |</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">java.io.InputStream | dori.jasper.engine.JasperReport) "java.lang.String"</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">> </span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Subreport Expression</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Just like normal report designs, subreport designs are in fact </span> <span style="FONT-SIZE: 9pt">dori.jasper.engine.JasperReport</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">objects. Those are obtained after compiling a </span> <span style="FONT-SIZE: 9pt">dori.jasper.engine.design.JasperDesign </span> <span style="FONT-SIZE: 10pt">object</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">as seen in the </span> <em><span style="FONT-SIZE: 10pt">3.2 Compiling Report Designs </span></em> <span style="FONT-SIZE: 10pt">section of this book.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt; COLOR: #c1c1c1">The JasperReports Ultimate Guide</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Page 64</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">We have seen that the text field elements have an expression that will be evaluated to obtain the text</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">content to display. The image elements have an expression representing the source of the image to</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">display. In the same way, subreport elements have an expression that is evaluated at runtime, in order</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">to obtain the source of the </span> <span style="FONT-SIZE: 9pt">dori.jasper.engine.JasperReport </span> <span style="FONT-SIZE: 10pt">object to load.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The so-called subreport expression is introduced by the </span> <span style="FONT-SIZE: 9pt"><subreportExpression> </span> <span style="FONT-SIZE: 10pt">element and can</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">return values from the following classes:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">java.lang.String</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">java.io.File</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">java.net.URL</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">java.io.InputStream</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">dori.jasper.engine.JasperReport</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">When the subreport expression returns a </span> <span style="FONT-SIZE: 9pt">java.lang.String </span> <span style="FONT-SIZE: 10pt">value, the engine will try to</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">see whether the value represents an URL from which to load the subreport design object. If</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">it is not a valid URL representation, it will try to locate a file on disk and load the subreport</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">design from it, assuming that the value represents a file name. If no file is found, it will</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">finally assume that the string value represents the location of a classpath resource and will</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">try to load the subreport design from there. Only if all those fail, an exception will be</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">thrown.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">If the image expression class is not specified using the </span> <span style="FONT-SIZE: 9pt">class </span> <span style="FONT-SIZE: 10pt">attribute, it is assumed to be</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">java.lang.String</span> <span style="FONT-SIZE: 10pt">, by default.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Caching Subreports</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">A subreport element can load different subreport designs with every evaluation, giving you great</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">flexibility in shaping you documents.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">However, most of the time, the subreport elements on a report are in fact static and their source do not</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">necessarily change with every new evaluation of the subreport expression. In the majority of cases, the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">subreport designs are loaded from fixed locations: files on disk or static URLs.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">If the same subreport design is filled multiple times on a report, there is no point on loading the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">subreport design object from the source file every time we have to fill it with data.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">We can instruct the reporting engine to cache this particular subreport design object. This way we are</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">making sure that the subreport design will be loaded from disk or from its particular location only once</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">and then it will only be reused every time it has to be filled.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">By setting the </span> <span style="FONT-SIZE: 9pt">isUsingCache </span> <span style="FONT-SIZE: 10pt">attribute to </span> <span style="FONT-SIZE: 9pt">"true"</span> <span style="FONT-SIZE: 10pt">, the reporting engine will try to recognize</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">previously loaded subreport design objects, using their specified source. For example, it will recognize</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">a subreport object if its source is a file name that it has already loaded, or if it is the same URL.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">This caching functionality is available only for subreport elements that have expressions returning</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">java.lang.String </span> <span style="FONT-SIZE: 10pt">objects as the subreport design source, representing file names, URLs or</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">classpath resources. That's because the engine uses the subreport source string as the key to recognize</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">that it is the same subreport design that it has already cached.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt; COLOR: #c1c1c1">The JasperReports Ultimate Guide</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Page 65</span> </div> <div style="TEXT-INDENT: 32.15pt"> <strong><font size="5"><span>9.1 Subreport Parameters</span></font></strong> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Since subreports are normal reports themselves, they are compiled or filled in the same way. This</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">means that they also require a data source from which to get the data when they are filled and that can</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">also receive parameters, for the additional information they have to use when being filled.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">There are two ways to supply the parameter values to a subreport and they can be used simultaneously,</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">if desired.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">You can supply a map containing the parameter values, like we do when filling a normal report with</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">data, using one of the </span> <span style="FONT-SIZE: 9pt">fillReportXXX() </span> <span style="FONT-SIZE: 10pt">methods exposed by the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">dori.jasper.engine.JasperFillManager </span> <span style="FONT-SIZE: 10pt">class (see the </span> <em><span style="FONT-SIZE: 10pt">3.4 Filling Reports </span></em> <span style="FONT-SIZE: 10pt">chapter to refresh</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">your memory).</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">This can be achieved if you use the </span> <span style="FONT-SIZE: 9pt"><parametersMapExpression> </span> <span style="FONT-SIZE: 10pt">element, which introduces the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">expression that will be evaluated in order to obtain the specified parameter map. This expression should</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">always return a </span> <span style="FONT-SIZE: 9pt">java.util.Map </span> <span style="FONT-SIZE: 10pt">object in which the keys are the parameter names.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">In addition to or instead of supplying the parameter values in a map, you can supply the parameter</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">values individually, one by one, using a </span> <span style="FONT-SIZE: 9pt"><subreportParameter> </span> <span style="FONT-SIZE: 10pt">element for each parameter you are</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">interested in. In such case, you have to specify the name of the corresponding parameter using the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">mandatory </span> <span style="FONT-SIZE: 9pt">name </span> <span style="FONT-SIZE: 10pt">attribute and you have to provide an expression that will be evaluated at runtime to</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">obtain the value for that particular parameter, value that will be supplied to the subreport filling</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">routines.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Note that you can use both ways to provide subreport parameter values, simultaneously. When this</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">happens, the parameter values specified individually, using the <subreportParameter> element, will</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">override the parameters values present in the parameter map, that correspond to the same subreport</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">parameter. If the map does not contain corresponding parameter values already, the individually</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">specified parameter values will be added to the map.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Attention! When you supply the subreport parameter values, you have to be aware that the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">reporting engine will affect the </span> <span style="FONT-SIZE: 9pt">java.util.Map </span> <span style="FONT-SIZE: 10pt">object it receives, adding the built-in</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">report parameter values that correspond to the subreport. This map is also affected by the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">individually specified subreport parameter values, as already explained above.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">In order to avoid altering the original </span> <span style="FONT-SIZE: 9pt">java.util.Map </span> <span style="FONT-SIZE: 10pt">object that you send, you can wrap it</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">in a different map, before supplying it to the subreport filling process like this:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">new HashMap(myOriginalMap)</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">This way, your original map object remains unaffected and modifications are made to the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">wrapping map object.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">This is useful especially when you want to supply to your subreport the same set of</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">parameters that the master report has received and you use the built-in</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">REPORT_PARAMETERS_MAP </span> <span style="FONT-SIZE: 10pt">report parameter of the master report. However, you don't want</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">to affect the value of this built-in parameter and you will wrap it like this:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><parametersMapExpression></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">new HashMap($P{REPORT_PARAMETERS_MAP})</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"></parametersMapExpression></span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt; COLOR: #c1c1c1">The JasperReports Ultimate Guide</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Page 66</span> </div> <div style="TEXT-INDENT: 32.15pt"> <strong><font size="5"><span>9.2 Subreport Data Source</span></font></strong> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Subreports need a data source in order to generate their content, just like normal report do.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">In the </span> <em><span style="FONT-SIZE: 10pt">3.4 Filling Reports </span></em> <span style="FONT-SIZE: 10pt">chapter of this book we have seen that when filling a report you have to</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">supply either a data source object or a connection object, depending on that particular report type. That</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">is if it has an internal SQL query and you want to have it executed to obtain the report data or you</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">supply the report data yourself.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Subreports behave in the same way and expect to receive the same kind of input when they are being</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">filled.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">You can supply to your subreport either a data source using the </span> <span style="FONT-SIZE: 9pt"><dataSourceExpression> </span> <span style="FONT-SIZE: 10pt">element</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">or a JDBC connection for the engine to execute the subreport's internal SQL query using the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt"><connectionExpression> </span> <span style="FONT-SIZE: 10pt">element. These two XML elements cannot be both present at the same</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">time in a subreport element declaration. This is because you cannot supply both a data source and a</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">connection for your subreport. You have to decide on one of them and stick to it.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The report engine expects that the data source expression returns a</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">dori.jasper.engine.JRDataSource </span> <span style="FONT-SIZE: 10pt">object and that the connection expression returns a</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">java.sql.Connnection </span> <span style="FONT-SIZE: 10pt">object, whichever is present.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">You can see how subreports work, if you check the </span> <em><span style="FONT-SIZE: 10pt">subreport </span></em> <span style="FONT-SIZE: 10pt">sample.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt; COLOR: #c1c1c1">The JasperReports Ultimate Guide</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Page 67</span> </div> <div style="TEXT-INDENT: 44.15pt"> <strong><font size="6"><span>10 Advanced JasperReports</span></font></strong> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Previous chapters have presented the core functionality that most people will get to use when working</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">with the JasperReports library.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">However, some complex requirements of your specific applications might force you to dig deeper into</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">the JasperReports functionality in order to adapt it to suit you needs.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">In the following sections we are going to take a closer look at those aspects that are likely to interest</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">you if you'll want to make full benefit from the use of the JasperReports library.</span> </div> <div style="TEXT-INDENT: 32.15pt"> <strong><font size="5"><span>10.1 XML Report Designs Loading and Writing</span></font></strong> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">In the </span> <em><span style="FONT-SIZE: 10pt">3.2 Compiling Report Designs </span></em> <span style="FONT-SIZE: 10pt">chapter we have explained how report designs pass from their</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">initial XML form into the compiled form, before being used to generate full-featured documents.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The engine first parses the XML report design and creates the in-memory representation of it by</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">instantiating and preparing a </span> <span style="FONT-SIZE: 9pt">dori.jasper.engine.design.JasperDesign </span> <span style="FONT-SIZE: 10pt">object. This object is</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">then subject to various validation checks and suffers the compilation process that produces a</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">corresponding </span> <span style="FONT-SIZE: 9pt">dori.jasper.engine.JasperReport </span> <span style="FONT-SIZE: 10pt">object.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">But in certain cases, in your application, you might want to manually load the XML report design into a</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">dori.jasper.engine.design.JasperDesign </span> <span style="FONT-SIZE: 10pt">object, without immediately compiling it. Such</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">scenarios might be common for applications that programmatically create report designs and use the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">XML form to store them temporary or permanently.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Loading </span> <span style="FONT-SIZE: 9pt">dori.jasper.engine.design.JasperDesign </span> <span style="FONT-SIZE: 10pt">objects from XML report design can be</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">easily by calling one of the public static </span> <span style="FONT-SIZE: 9pt">load() </span> <span style="FONT-SIZE: 10pt">methods exposed by the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">dori.jasper.engine.xml.JRXmlLoader </span> <span style="FONT-SIZE: 10pt">class. This way you can load report design object from</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">XML content store in filed or that is been read from input streams.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The process opposed to the XML report design loading process is the generation of the XML form for a</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">given report design object.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">As seen above, sometimes report designs are created programmatically, using the JasperReports API.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The report design objects obtained this way can be serialized, for disk storage or transfer over the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">network, but they also can be stored in XML format.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">You can obtain the XML representation of a given report design object by using one of the public static</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">writeReport() </span> <span style="FONT-SIZE: 10pt">methods exposed by the </span> <span style="FONT-SIZE: 9pt">dori.jasper.engine.xml.JRXmlWriter </span> <span style="FONT-SIZE: 10pt">utility class.</span> </div> <div style="TEXT-INDENT: 32.15pt"> <strong><font size="5"><span>10.2 Implementing Data Sources</span></font></strong> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">JasperReports library comes with several default implementations of the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">dori.jasper.engine.JRDataSource </span> <span style="FONT-SIZE: 10pt">interface. This interface is used to supply the report data</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">when invoking the report filling process, as explained in the previous chapters of this book.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">These default implementations let you generate reports using data from relational databases retrieved</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">through JDBC, from Java Swing tables or from collections and arrays of JavaBeans objects.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">But maybe your application data that your are trying to display in your reports has a special structure or</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">is organized in a very particular way preventing you from using any of the default implementations of</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">the data source interface that come with the library.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">In such situations, you will have to create custom implementations for the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">dori.jasper.engine.JRDataSource </span> <span style="FONT-SIZE: 10pt">interface, in order to wrap your special report data, so that</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">the reporting engine can understand and use it when generating the reports for you.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt; COLOR: #c1c1c1">The JasperReports Ultimate Guide</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Page 68</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Creating a custom implementation for the </span> <span style="FONT-SIZE: 9pt">dori.jasper.engine.JRDataSource </span> <span style="FONT-SIZE: 10pt">interface is not</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">very difficult since you have to implement only two methods.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The first one, the </span> <span style="FONT-SIZE: 9pt">next() </span> <span style="FONT-SIZE: 10pt">method, is called by the reporting engine every time it wants the current</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">pointer to advance to the next virtual record in the data source.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The other, the </span> <span style="FONT-SIZE: 9pt">getFieldValue() </span> <span style="FONT-SIZE: 10pt">method, is called by the reporting engine with every iteration in the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">data source to retrieve the value for each report field.</span> </div> <div style="TEXT-INDENT: 32.15pt"> <strong><font size="5"><span>10.3 Customizing Viewers</span></font></strong> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The JasperReports library comes with built-in viewers that allow you to display the reports stored in the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">library's proprietary format or to preview your report designs when you create them.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">These viewers are represented by the following two classes:</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <span style="FONT-SIZE: 9pt">dori.jasper.view.JasperViewer : </span> <span style="FONT-SIZE: 10pt">You use this class to view generated reports, either as</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">in-memory objects or serialized objects on disk or even stored in XML format.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">_ </span> <span style="FONT-SIZE: 9pt">dori.jasper.view.JasperDesignViewer : </span> <span style="FONT-SIZE: 10pt">This class can be used to preview report</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">designs, either in XML form or compiled form.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">But these default viewers might not suit everybody's needs and therefore you might consider</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">customizing them so they adapt to certain application requirements.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">In order to do that, you should be aware that these viewers use in fact other, more basic visual</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">components that come with the JasperReports library.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The report viewer mentioned above use the visual component represented by the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">dori.jasper.view.JRViewer </span> <span style="FONT-SIZE: 10pt">class and its companions. It is in fact a special</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">javax.swing.JPanel </span> <span style="FONT-SIZE: 10pt">component that is capable of displaying generated reports and that can be</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">easily incorporated in other Java Swing based applications or applets.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">If the functionality of this basic visual component is not sufficient for what you need, you can adapt it</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">by subclassing it. If for example you would want to have an extra button on the toolbar of this viewer,</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">you might consider extending the component and add that button yourself in the new visual component</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">you obtain by subclassing.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">This can be seen in the </span> <em><span style="FONT-SIZE: 10pt">webapp </span></em> <span style="FONT-SIZE: 10pt">sample, where the "Printer Applet" displays a customized version of the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">report viewer with an extra button in the toolbar.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Another very important issue is that the default report viewer that comes with the library does not know</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">how to deal with document hyperlinks that point to external resources. It only deals with local</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">references and can redirect the viewer to corresponding local anchor.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">However, JasperReports offers you the possibility to handle yourself the clicks made on document</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">hyperlinks that point to external documents and not local anchors.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The only thing you have to do in order to achieve this, is to implement the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">dori.jasper.view.JRHyperlinkListener </span> <span style="FONT-SIZE: 10pt">interface and to add to register with the viewer</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">component an instance of this listener class, using the </span> <span style="FONT-SIZE: 9pt">addHyperlinkListener() </span> <span style="FONT-SIZE: 10pt">method exposed</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">by the </span> <span style="FONT-SIZE: 9pt">dori.jasper.view.JRViewer </span> <span style="FONT-SIZE: 10pt">class.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">By doing this, you make sure the viewer will also call your implementation of the </span> <span style="FONT-SIZE: 9pt">gotoHyperlink()</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">method in which you handle yourself the external references.</span> </div> <div style="TEXT-INDENT: 32.15pt"> <strong><font size="5"><span>10.4 Exporting to New Output Formats</span></font></strong> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">The JasperReports library continually evolves and improves. Among the features that are likely to be</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">introduced with time is the ability to export to new documents formats, besides PDF, HTML and XML.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">In order to extend diversify in this direction, without affecting the existing functionality, JasperReports</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">provides those interested in this subject an interface for them to implement, in case they want to create</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">exporter classes that transform the generated documents into new output formats.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">This way, if you need to export your reports into a special output format that is not yet available in the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">core library, you might decide to implement yourself the </span> <span style="FONT-SIZE: 9pt">dori.jasper.engine.JRExporter</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">interface.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt; COLOR: #c1c1c1">The JasperReports Ultimate Guide</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">Page 69</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Before deciding to implement this interface, it is important for you to understand how the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">implementation is expected to function.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">All the input data the exporter might need should be supplied to it using the so-called exporter</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">parameters, before the exporting process is started.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">This is because the exporting process will be always invoked by calling the </span> <span style="FONT-SIZE: 9pt">exportReport() </span> <span style="FONT-SIZE: 10pt">method</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">of the </span> <span style="FONT-SIZE: 9pt">dori.jasper.engine.JRExporter </span> <span style="FONT-SIZE: 10pt">interface, and this method does not receive any</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">parameters itself, when called. The exporter parameters have to be already set using the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">setParameter() </span> <span style="FONT-SIZE: 10pt">method on the exporter instance you are working with, before launching the export</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">task.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">You might choose to bulk set all your exporter parameters using the </span> <span style="FONT-SIZE: 9pt">setParameters() </span> <span style="FONT-SIZE: 10pt">method which</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">receives a </span> <span style="FONT-SIZE: 9pt">java.util.Map </span> <span style="FONT-SIZE: 10pt">object containing the parameter values. The keys in this map should be</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">instances of the </span> <span style="FONT-SIZE: 9pt">dori.jasper.engine.JRExporterParameter </span> <span style="FONT-SIZE: 10pt">class, as you would supply when</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">individually calling the </span> <span style="FONT-SIZE: 9pt">setParameter() </span> <span style="FONT-SIZE: 10pt">method for each of your exporter parameters.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Note that no matter what the type of output your exporter produces, you will be using parameters to</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">indicate to the exporter where to place or send this output.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">Such parameter might be called OUT parameters.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">For example, if you want your exporter to send the output it produces to an output stream, you will</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">supply the </span> <span style="FONT-SIZE: 9pt">java.io.OutputStream </span> <span style="FONT-SIZE: 10pt">object reference to the exporter using a parameter, probably</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">identified by the </span> <span style="FONT-SIZE: 9pt">dori.jasper.engine.JRExporterParameter.OUTPUT_STREAM </span> <span style="FONT-SIZE: 10pt">constant.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">It is recommended to use the public constants of the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">dori.jasper.engine.JRExporterParameter </span> <span style="FONT-SIZE: 10pt">class to identify the parameters you set in your</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">exporters and only if you don't find one available for a particular setting you have to make in your</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">exporter, to extend this class to add new constants. This can be seen for the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">dori.jasper.engine.export.JRXmlExporter</span> <span style="FONT-SIZE: 10pt">, where special parameter identifier where created</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">by subclassing the </span> <span style="FONT-SIZE: 9pt">dori.jasper.engine.JRExporterParameter </span> <span style="FONT-SIZE: 10pt">class in the</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 9pt">dori.jasper.engine.export.JRXmlExporterParameter </span> <span style="FONT-SIZE: 10pt">class.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">You don't have to start from scratch when implementing the exporter interface, because there is a</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">convenience abstract class called </span> <span style="FONT-SIZE: 9pt">dori.jasper.engine.JRAbstractExporter </span> <span style="FONT-SIZE: 10pt">that at least deals</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 20pt; LINE-HEIGHT: normal"> <span style="FONT-SIZE: 10pt">with parameter management for you.</span> </div> <div style="MARGIN-BOTTOM: 0pt; TEXT-INDENT: 24pt; LINE-HEIGHT: normal">   </div> </div> </div> </div> </div> </div> <!--PC和WAP自适应版--> <div id="SOHUCS" sid="1289157447071637504"></div> <script type="text/javascript" src="/views/front/js/chanyan.js"></script> <!-- 文章页-底部 动态广告位 --> <div class="youdao-fixed-ad" id="detail_ad_bottom"></div> </div> <div class="col-md-3"> <div class="row" id="ad"> <!-- 文章页-右侧1 动态广告位 --> <div id="right-1" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad"> <div class="youdao-fixed-ad" id="detail_ad_1"> </div> </div> <!-- 文章页-右侧2 动态广告位 --> <div id="right-2" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad"> <div class="youdao-fixed-ad" id="detail_ad_2"></div> </div> <!-- 文章页-右侧3 动态广告位 --> <div id="right-3" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad"> <div class="youdao-fixed-ad" id="detail_ad_3"></div> </div> </div> </div> </div> </div> </div> <div class="container"> <h4 class="pt20 mb15 mt0 border-top">你可能感兴趣的:(JasperReport报表)</h4> <div id="paradigm-article-related"> <div class="recommend-post mb30"> <ul class="widget-links"> <li><a href="/article/1835491101276991488.htm" title="数据仓库——维度表一致性" target="_blank">数据仓库——维度表一致性</a> <span class="text-muted">墨染丶eye</span> <a class="tag" taget="_blank" href="/search/%E8%83%8C%E8%AF%B5/1.htm">背诵</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E4%BB%93%E5%BA%93/1.htm">数据仓库</a> <div>数据仓库基础笔记思维导图已经整理完毕,完整连接为:数据仓库基础知识笔记思维导图维度一致性问题从逻辑层面来看,当一系列星型模型共享一组公共维度时,所涉及的维度称为一致性维度。当维度表存在不一致时,短期的成功难以弥补长期的错误。维度时确保不同过程中信息集成起来实现横向钻取货活动的关键。造成横向钻取失败的原因维度结构的差别,因为维度的差别,分析工作涉及的领域从简单到复杂,但是都是通过复杂的报表来弥补设计</div> </li> <li><a href="/article/1835253081579810816.htm" title="三大财报之间的关系" target="_blank">三大财报之间的关系</a> <span class="text-muted">木子读吧</span> <div>「今天是木子读吧陪你的第958天」三大财务报表之间是紧密联系的,就像之前的这篇文章【用相亲的眼光看透三大财务报表】,它们之间就好像骨骼、肌肉和血液的关系。每张表中任意科目的数字变动,都会引起三张表中与之相关科目的变动。资产负债表中有个恒等式:资产(左边)=负债+所有者权益(右边)。也就是说,一项资产的增加,来源于一项负债的增加或所有者权益的增加。你可以把整个利润表当作是所有者权益科目,因为利润表科</div> </li> <li><a href="/article/1835188747822526464.htm" title="mysql查询统计聚合函数" target="_blank">mysql查询统计聚合函数</a> <span class="text-muted">三小皮</span> <a class="tag" taget="_blank" href="/search/mysql/1.htm">mysql</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%BA%93/1.htm">数据库</a> <div>业务中用户统计报表使用,查询字段使用聚合函数+条件,快速实现报表统计。SELECTMIN(s.org_name)ASorgName,s.way_nameASwayName,COUNT(s.id)ASwaybillTotal,SUM(s.take_weight)AStakeWeightTotal,SUM(s.revert_weight)ASrevertWeightTotal,SUM(s.settle</div> </li> <li><a href="/article/1834933798836465664.htm" title="公司的资产有哪些?" target="_blank">公司的资产有哪些?</a> <span class="text-muted">流年践行</span> <div>说起资产,你会不会想到:货币资金、预付款项、存货、流动资产、固定资产、无形资产等等,这些在资产负债表中经常出现的财务概念?今天我们不是来讨论资产的明细科目,而是讲一下关于怎么看待资产和资产的一些重要认知。如何看待企业的资产呢?只有在未来能够产生收益的经济资源,才是资产。企业所拥有的资产,远远大于财务报表中所记录的资产。比如:假如一家蛋糕店接了一个特殊订单,为此买了一批特殊形状的模具,蛋糕做完之后,</div> </li> <li><a href="/article/1834930250614665216.htm" title="学点金融学——财务报表之现金流量表" target="_blank">学点金融学——财务报表之现金流量表</a> <span class="text-muted">静观者</span> <div>现金流量表反映的是企业的风险状况以及持续经营的能力。现金流量表主要就是对现金流入和流出的描述,按照公司从事的活动分为经营活动、投资活动和筹资活动。经营活动流入的现金有销售、税收以及其他与经营活动有关的现金收入。经营活动流出的现金有采购、人工、税收以及其他与经营活动有关的现金支出。投资活动的现金流量主要是指企业对内对外投资的支出和收到之前投资回报所产生的现金流量。融资活动的现金流量主要是指债务融资或</div> </li> <li><a href="/article/1834823217777307648.htm" title="如何快速的构建企业运维可视化大屏" target="_blank">如何快速的构建企业运维可视化大屏</a> <span class="text-muted">益达_glmsb</span> <div>基于AIOps理念研发的新一代运维监大屏全盘展示IT运行状态,减轻运维人员的重复性工作量,提高IT系统排错速度,加速运维知识学习积累。图片1.png领先的数据可视化平台,把IT运维化繁为简图片2.jpg图片3.png图片4.png图片5.png图片6.png全面提升IT运维管理水平1.直接导出精美的IT运行可视化报表图片7.png2.资源分析对比图片8.png3.自动生成监控项运行“脑图”图片9.</div> </li> <li><a href="/article/1834692296965189632.htm" title="多表逐级关联报表,使用poi方法导出excel" target="_blank">多表逐级关联报表,使用poi方法导出excel</a> <span class="text-muted">LCF_全博</span> <div>难点要求多表关联导出,简单介绍:有A1表,A2表,B表,C表,A1和A2是一对多的关系,B表和A1表也是一对多的关系,C表和B表是一对多的关系。这是简化的业务逻辑,表之间的关系就类似这种。完成对关联导出。实现思路熟悉poi导出的可能会知道,报表的导出总体思路是将数据按照excel的每一行去写入数据的,假如是有序的数据还好说点,比如单表的导出,直接单表查询出来,循环写入每一个excel行就行,这种做</div> </li> <li><a href="/article/1834596036648202240.htm" title="不读财报就出局六期D3" target="_blank">不读财报就出局六期D3</a> <span class="text-muted">邮吻</span> <div>三大财务报表一:利润表代表公司一段时间有没有赚到钱。公司到营业收入减去销,管,研等费用,利息还有所得税剩下的就是净利润,利润表是预估概念运用到个人层面就是工资减去衣食住行育乐,红白喜事,还有所得税剩下的钱。二:资产负债表公司利润表赚的钱兵分两路,放到左边是处理资产,放在右边是处理负债和股东权益左边等于右边。代表某一天公司的资产负债情况。运用到个人层面就是存下的钱,放左边是给手头留点现金,借钱给朋友</div> </li> <li><a href="/article/1834465528429768704.htm" title="我今天的工作和学习" target="_blank">我今天的工作和学习</a> <span class="text-muted">bulaodexin</span> <div>图片发自App今天回家晚了。匆匆忙忙把特训营第八天的课程学完,效果不理想,不知什么原因,就觉得老师的语速好快,暂停倒回了好多次,迷你图没有成功,抽奖前三名的知识也没能全弄懂,导图快做完了又遇到电脑故障重启,总之很有点失望。想想昨天的可是被储君老师老师钦点表扬的,一下子感觉从天上掉到了地下。今天学习的内容是用条件格式扮靓报表,内容主要包括:1、基础用法:(1)突出显示单元格规则(2)快速查找重复值(</div> </li> <li><a href="/article/1834463982619029504.htm" title="月之暗面对谈 Zilliz:长文本和 RAG 如何选择?" target="_blank">月之暗面对谈 Zilliz:长文本和 RAG 如何选择?</a> <span class="text-muted">冻感糕人~</span> <a class="tag" taget="_blank" href="/search/%E4%BA%BA%E5%B7%A5%E6%99%BA%E8%83%BD/1.htm">人工智能</a><a class="tag" taget="_blank" href="/search/%E5%A4%A7%E6%95%B0%E6%8D%AE/1.htm">大数据</a><a class="tag" taget="_blank" href="/search/%E7%AE%97%E6%B3%95/1.htm">算法</a><a class="tag" taget="_blank" href="/search/%E8%87%AA%E7%84%B6%E8%AF%AD%E8%A8%80%E5%A4%84%E7%90%86/1.htm">自然语言处理</a><a class="tag" taget="_blank" href="/search/ai%E5%A4%A7%E6%A8%A1%E5%9E%8B/1.htm">ai大模型</a><a class="tag" taget="_blank" href="/search/RAG/1.htm">RAG</a><a class="tag" taget="_blank" href="/search/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0/1.htm">机器学习</a> <div>01长文本与RAG通用对比准确率:通常情况下长文本优于RAG长文本:可更加综合的去分析所有相关的内容,提取相关数字,生成图表,效果尚可。RAG:更适合找到一段或者是几段可能相关的段落。如果希望大模型能够对问题有全局的认识,比较困难。如,根据上市公司的2020年财务报表,绘制图表,直接用RAG可能效果就不是很好。长文本在准确性上表现好的原因,以及长度与准确性选择长文本处理之后,会做对齐和专门的Ben</div> </li> <li><a href="/article/1834229251411374080.htm" title="苍洱风光,泸沽湖畔——放空在彩云之南" target="_blank">苍洱风光,泸沽湖畔——放空在彩云之南</a> <span class="text-muted">肉丸子不圆</span> <div>自从毕业工作了以后,再也没能像读书时一样随时背上背包,来一次说走就走的旅行。那个曾经在象牙塔里没心没肺拿着学生证到处疯玩的我,如今已经换下白衬衫和帆布鞋,在格子间里一边报表一边喝咖啡提神。同事送过来一份鲜花饼下午茶,突然觉得,是时候买一张机票飞到彩云之南,放空自己了。对云南的向往,最初源于出现在影视剧里的玉龙雪山和虎跳峡,仿佛象征着神圣的爱情。后来读大冰的书,也想去看看丽江的古城、大理的苍山洱海,</div> </li> <li><a href="/article/1834142041542586368.htm" title="文本处理三剑客之--awk" target="_blank">文本处理三剑客之--awk</a> <span class="text-muted">Hu_O&M</span> <a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a><a class="tag" taget="_blank" href="/search/bash/1.htm">bash</a><a class="tag" taget="_blank" href="/search/%E8%BF%90%E7%BB%B4/1.htm">运维</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a> <div>一、简介awk是一个处理文本的编程语言工具,能用简短的程序处理标准输入或文件、数据排序、计算以及生成报表等等。awk处理的工作方式与数据库类似,支持对记录和字段处理,这也是grep和sed不能实现的。在awk中,缺省的情况下将文本文件中的一行视为一个记录,逐行放到内存中处理,而将一行中的某一部分作为记录中的一个字段。用1,2,3...数字的方式顺序表示行(记录)中的不同字段。用$后跟数字,引用对应</div> </li> <li><a href="/article/1833972006551384064.htm" title="界面控件DevExpress中文教程:如何PDF图形对象的可见性?" target="_blank">界面控件DevExpress中文教程:如何PDF图形对象的可见性?</a> <span class="text-muted">界面开发小八哥</span> <a class="tag" taget="_blank" href="/search/pdf/1.htm">pdf</a><a class="tag" taget="_blank" href="/search/devexpress/1.htm">devexpress</a><a class="tag" taget="_blank" href="/search/winform/1.htm">winform</a><a class="tag" taget="_blank" href="/search/%E7%95%8C%E9%9D%A2%E6%8E%A7%E4%BB%B6/1.htm">界面控件</a><a class="tag" taget="_blank" href="/search/WPF/1.htm">WPF</a><a class="tag" taget="_blank" href="/search/ui/1.htm">ui</a> <div>DevExpress拥有.NET开发需要的所有平台控件,包含600多个UI控件、报表平台、DevExpressDashboardeXpressApp框架、适用于VisualStudio的CodeRush等一系列辅助工具。屡获大奖的软件开发平台DevExpress近期重要版本v24.1已正式发布,该版本拥有众多新产品和数十个具有高影响力的功能,可为桌面、Web和移动应用提供直观的解决方案,全面解决各</div> </li> <li><a href="/article/1833918540491616256.htm" title="Python自动化办公2.0 即将发布" target="_blank">Python自动化办公2.0 即将发布</a> <span class="text-muted">百里图书</span> <a class="tag" taget="_blank" href="/search/%E8%87%AA%E5%8A%A8%E5%8C%96/1.htm">自动化</a><a class="tag" taget="_blank" href="/search/%E4%BA%BA%E5%B7%A5%E6%99%BA%E8%83%BD/1.htm">人工智能</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a> <div>第一节课:数据整理与清洗第二节课:数据筛选、过滤与排序第三节课:高级数据处理技巧第四节课:数据可视化与实践案例第五节课:统计分析与报表第六节:常见的Excel报表与下方的课程形成知识体系:Python自动化办公(面向2020,Python3.7,不断更新ing)_在线视频教程-CSDN程序员研修院https://edu.csdn.net/course/detail/28031Python机器学习教</div> </li> <li><a href="/article/1833705108714647552.htm" title="神奇酷炫的下拉菜单" target="_blank">神奇酷炫的下拉菜单</a> <span class="text-muted">紫藤11</span> <div>下拉菜单目前公司的销售报表上,用有这个功能,真心方便,感谢小哈录制的抖音视频,但操作更简单。一、基本用法直接按住Alt+↓即可快速生成,注意:想要实现这样的功能前提是已经输入部分内容二、进阶用法1.提示信息2.出错警告3.圈释无效信息第一次作用圈释无效信息的功能三、动态下拉列表选取数据→定义名称→数据验证→序列→输入=名称四、快速录入当前时间=now()数据验证设置单元格格式五、借贷只能一方输入选</div> </li> <li><a href="/article/1833591484486610944.htm" title="简单易懂,财务报表分析学习笔记:市净率" target="_blank">简单易懂,财务报表分析学习笔记:市净率</a> <span class="text-muted">偷懒苦行僧</span> <div>一、市净率的定义市净率(Price-to-BookRatio,简称P/BPBR)指的是每股股价与每股净资产的比值;市净率=股票市价÷每股净资产或市净率=股票总市值÷净资产净资产=资产总额-负债总额二、市净率的作用市净率既反映了市场对于企业的评价,也为投资决策提供参考;在股票交易市场中,股票价格是由交易各方的实际交易价格确定,能够及时地反映出市场中投资者对企业的评价,再以净资产的账面价值作比较,为投</div> </li> <li><a href="/article/1833465679949426688.htm" title="成为数据分析师的必要条件" target="_blank">成为数据分析师的必要条件</a> <span class="text-muted">HsuHeinrich</span> <a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90/1.htm">数据分析</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90/1.htm">数据分析</a> <div>开篇成为数据分析师的必要条件作为一名成熟的数据分析师,那必然是要头顶Python,脚踩SQL,左手一个Tableau,右手一个Excel。能取数,会报表,埋点AB两不误,分析落地显价值。那在日常工作中具体需要具备哪些技能呢?笔者根据个人工作学习,对自己做了个技能画像。接下来,笔者将从工具应用、理论基础、数字基建、分析思维四个方面介绍数据分析的必要条件。对其中一些基本技能附上基础教程,帮助初学者迈进</div> </li> <li><a href="/article/1833343135984480256.htm" title="Python API操作RocketMQ" target="_blank">Python API操作RocketMQ</a> <span class="text-muted">京城小筑</span> <a class="tag" taget="_blank" href="/search/%23/1.htm">#</a><a class="tag" taget="_blank" href="/search/Python%E7%BC%96%E7%A8%8B/1.htm">Python编程</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a> <div>背景:开发背景:公司相关报表需求需要将订单业务数据同步至RocketMQ中,由于需要保证开发的一致性(多个部门协同开发),所以采用读取Hive离线数据的方式通过PythonAPI写入RocketMQ中,便于其他开发同事调用~开发环境:本地调试系统MacPython3.7.5rocketmq0.4.4(Python模块)rocketmq-client-python2.0.0(Python模块)服务器</div> </li> <li><a href="/article/1833295112302587904.htm" title="终端滑模matlab程序,机器人轨迹跟踪控制方法研究(含MATLAB程序)" target="_blank">终端滑模matlab程序,机器人轨迹跟踪控制方法研究(含MATLAB程序)</a> <span class="text-muted">得陇而望蜀者</span> <a class="tag" taget="_blank" href="/search/%E7%BB%88%E7%AB%AF%E6%BB%91%E6%A8%A1matlab%E7%A8%8B%E5%BA%8F/1.htm">终端滑模matlab程序</a> <div>机器人轨迹跟踪控制方法研究(含MATLAB程序)(课题申报表,任务书,开题报告,中期检查表,外文翻译,论文15300字,程序,答辩PPT)摘要机器人是一类复杂的、具有不确定性的、多输入多输出非线性时变系统。滑模变结构控制对系统参数和外部扰动等不确定性具有不变性,因此非常适合于机器人的控制。本文主要研究了机器人的滑模轨迹跟踪控制。首先简要介绍机器人轨迹跟踪方法和滑模控制的基本原理,然后着重阐述奇异终</div> </li> <li><a href="/article/1833266781045747712.htm" title="2021年05月1-11检视" target="_blank">2021年05月1-11检视</a> <span class="text-muted">成长为价值投资者</span> <div>5月目标:3日前完成应收账款更新---增加逾期并作为绩效的扣除项,不停与人沟通交流,好处增加催货款的主动性,财务控制作用,坏处就得罪人,增加日常工作量。考虑增加奖励项。工行贷款进行时,兴业贷款进行时。11日前完成月度数据分析--完成。15日前完成相关税务报表--完成。24日凭证整理装订投资及紫微斗数阅读,完善年度计划,目标不会高于梦想,所以自己的梦想不设限!一、事业(25分)目标:有老板的全局思维</div> </li> <li><a href="/article/1833229293480669184.htm" title="老板视角的可视化分析" target="_blank">老板视角的可视化分析</a> <span class="text-muted">qq_43696218</span> <a class="tag" taget="_blank" href="/search/%E4%BF%A1%E6%81%AF%E5%8F%AF%E8%A7%86%E5%8C%96/1.htm">信息可视化</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90/1.htm">数据分析</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E6%8C%96%E6%8E%98/1.htm">数据挖掘</a> <div>明明在金蝶开发了报表,老板却看也不看,因为站在老板的视角,他想要的金蝶BI数据可视化分析大概是下面这样的:1、不用等,想要的分析马上就能做到点击刷新,马上就能更新数据,自动计算指标、分析数据;在分析过程中,随时可以修改图表的汇总、行列维度,或者自行筛选数据做分析,又或者立即针对某维度数据展开分析等。举个例子来说,就是当你在分析报表时,发现某门店、某产品的生产销售情况异常时,可以立即针对性地分析该门</div> </li> <li><a href="/article/1833229166246457344.htm" title="奥威-金蝶BI现金流量表模板,可借鉴、可套用" target="_blank">奥威-金蝶BI现金流量表模板,可借鉴、可套用</a> <span class="text-muted">qq_43696218</span> <a class="tag" taget="_blank" href="/search/%E4%BF%A1%E6%81%AF%E5%8F%AF%E8%A7%86%E5%8C%96/1.htm">信息可视化</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90/1.htm">数据分析</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E6%8C%96%E6%8E%98/1.htm">数据挖掘</a><a class="tag" taget="_blank" href="/search/%E8%B4%A2%E5%8A%A1%E5%88%86%E6%9E%90/1.htm">财务分析</a> <div>企业现金流一旦出了问题都是大问题,会直接影响到企业的日常运作,甚至直接关系到企业能不能继续存活,因此现金流量表是企业财务分析中重要报表之一,也是企业监控财务监控情况的重要手段之一。那么这么重要的一份现金流量表该怎么做?奥威-金蝶BI方案里有没有模板可供借鉴?BI现金流量表预期效果:直观的了解各项活动的流入流出情况,并知道资金占用是否合理;通过现金净额与利润的对比,就知道到底是不是真的赚钱了。为此,</div> </li> <li><a href="/article/1833154715513352192.htm" title="数据分析师之打杂入门--运营学习" target="_blank">数据分析师之打杂入门--运营学习</a> <span class="text-muted">爱数据爱分析</span> <div>接上篇数据分析师之打杂入门--数据技能学习(网址:https://www.jianshu.com/writer#/notebooks/41435296/notes/58416752)在经历了辛苦的业务学习、数据学习后,很多分析师们以为可以羽扇纶巾、指点江山、激扬数据、提出策略、指导业务发展了。然而现实是:1、今天拉个数据,明天换个统计口径再拉数据。2、本周开发个报表,下周叠加字段继续开发报表,加班</div> </li> <li><a href="/article/1833057506109255680.htm" title="2021-06-15" target="_blank">2021-06-15</a> <span class="text-muted">自我教练</span> <div>周一觉察关系践行打卡早上忙了一早上报表,汇报工作(至少一个月领导没来单位,这工作也照常运转)认真的去感受领导的言语,去听懂这话里的意思,至于没表达的更是意会不了,我们的沟通只要我能领会他语言表层的意思就不错,我的表述他也容易答非所问,在平和的语气语调中交流就很不错了。说到这里我想笑,不带评判是保持愉快顺畅交流的先决条件。报考的高级心理咨询师证书马上到,感觉自己更专业了。把爱好和工作同步发展。到退休</div> </li> <li><a href="/article/1832653116047192064.htm" title="页面小组件-表格封装(基础版)" target="_blank">页面小组件-表格封装(基础版)</a> <span class="text-muted">前端SkyRain</span> <a class="tag" taget="_blank" href="/search/Vue/1.htm">Vue</a><a class="tag" taget="_blank" href="/search/%E5%89%8D%E7%AB%AF/1.htm">前端</a><a class="tag" taget="_blank" href="/search/vue.js/1.htm">vue.js</a> <div>说明这一版封装的主要原因是当时有很多报表,数据列很多很多,基本在二十个左右。相应领导安排简洁代码,也为了偷懒,直接插槽循环搞起。其余是为了统一样式修改。组件源码暂无数据{{row[column.prop]}}exportdefault{name:'CustomTable',props:{tableData:{type:Array,default:()=>[]},headerCellStyle:{t</div> </li> <li><a href="/article/1832307295577534464.htm" title="ELK架构" target="_blank">ELK架构</a> <span class="text-muted">小楚同学呀~</span> <div>一、Logstash+elasticsearch+Kibana首先由Logstash分布于各个节点上搜集相关日志、数据,并经过分析、过滤后发送给远端服务器上elasticsearch进行存储。elasticsearch将数据以分片的形式压缩存储并提供多种API供用户查询,操作。用户也可以直观的通过配置KibanaWebPortal方便的对日志进行查询,并根据数据生成报表。优点:搭建简单,易于上手。</div> </li> <li><a href="/article/1832193471407026176.htm" title="一天" target="_blank">一天</a> <span class="text-muted">潘多拉简书</span> <div>单位因为一个报表,打了几通长长短短的电话,微信里各种文件佐证他们的理由。事不是不能做,只是关系理不顺,做起来名不正言不顺,况且这个事情本身做起来也不容易。不知道什么时候这种理不顺,上下不对应的关系什么时候才能结束,我估计暂时也无解。阿克塞尔罗德给我们的建议:不要嫉妒、不要作恶、赏罚分明、不耍小聪明。除此之外,还必须注意一点,阿克塞尔罗德游戏有一个前提条件,就是博弈的回合数要足够多,未来的利益要足够</div> </li> <li><a href="/article/1831967120292933632.htm" title="2018.4.2读财报第六期作业D4" target="_blank">2018.4.2读财报第六期作业D4</a> <span class="text-muted">杰克言JACKYAN</span> <div>独孤九剑京东方A.png今天的学习收获:1.现金占总资产比例是读财报时的重中之重。首先,三大报表先看现金流量表,然后,现金流量表中先看现金占总资产比例这个重要的财务指标。2.既然学财报,就不仅知道这个指标,还要弄清楚这个指标与其它财务指标的联动关系。现金占总资产比例这个指标就要与总资产周转率一起看的。3.判断现金占总资产比例这个指标要至少大于10%,特殊情况要大于25%,这样的公司“气”比较长。4</div> </li> <li><a href="/article/1831631435698630656.htm" title="2019-07-23" target="_blank">2019-07-23</a> <span class="text-muted">chen晨辰</span> <div>别傻了,吃喝玩乐那不是团建“为什么老板都对团建有这么大的积极性,我真的宁愿在办公室里做报表啊!”刚收到群发的团建信息,小李并没有很开心,反而有点儿无语,“难道老板真的认为大家一起出去吃吃喝喝、玩点儿老掉牙的游戏就能解压吗?就能增强团队凝聚力吗?难道不是换个地方玩手机吗?”不怪小李觉得无语,他们公司出了名的压力大,所以老板每个月都会组织一次团建活动,可是每次团建都是带着他们去吃海鲜、吃烧烤、唱K。老</div> </li> <li><a href="/article/1831501597297963008.htm" title="2019-02-12" target="_blank">2019-02-12</a> <span class="text-muted">笨得不同凡响</span> <div>专注K12竞品机构的朋友您们好:谢谢您们这么热爱我们群,我们欢迎大家来学习我们的模式,大家一起来真正给孩子们一个良好的学习氛围,培养孩子的良好学习习惯,为孩子在学习上提供真正的帮助。我们运用了真题试卷,我们采用线上打卡形式,从开始的图片,到现在的系统;从开始的手工报表反应打卡情况,到现在的智能分析统计,为孩子们建立线上学习轨迹,科学的分析孩子们的薄弱点,给出正确的学习方案。我们不断升级优化,我们是</div> </li> <li><a href="/article/73.htm" title="Hadoop(一)" target="_blank">Hadoop(一)</a> <span class="text-muted">朱辉辉33</span> <a class="tag" taget="_blank" href="/search/hadoop/1.htm">hadoop</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a> <div>今天在诺基亚第一天开始培训大数据,因为之前没接触过Linux,所以这次一起学了,任务量还是蛮大的。 首先下载安装了Xshell软件,然后公司给了账号密码连接上了河南郑州那边的服务器,接下来开始按照给的资料学习,全英文的,头也不讲解,说锻炼我们的学习能力,然后就开始跌跌撞撞的自学。这里写部分已经运行成功的代码吧.    在hdfs下,运行hadoop fs -mkdir /u</div> </li> <li><a href="/article/200.htm" title="maven An error occurred while filtering resources" target="_blank">maven An error occurred while filtering resources</a> <span class="text-muted">blackproof</span> <a class="tag" taget="_blank" href="/search/maven/1.htm">maven</a><a class="tag" taget="_blank" href="/search/%E6%8A%A5%E9%94%99/1.htm">报错</a> <div>转:http://stackoverflow.com/questions/18145774/eclipse-an-error-occurred-while-filtering-resources   maven报错: maven An error occurred while filtering resources   Maven -> Update Proje</div> </li> <li><a href="/article/327.htm" title="jdk常用故障排查命令" target="_blank">jdk常用故障排查命令</a> <span class="text-muted">daysinsun</span> <a class="tag" taget="_blank" href="/search/jvm/1.htm">jvm</a> <div>linux下常见定位命令: 1、jps      输出Java进程       -q       只输出进程ID的名称,省略主类的名称;       -m      输出进程启动时传递给main函数的参数;     &nb</div> </li> <li><a href="/article/454.htm" title="java 位移运算与乘法运算" target="_blank">java 位移运算与乘法运算</a> <span class="text-muted">周凡杨</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E4%BD%8D%E7%A7%BB/1.htm">位移</a><a class="tag" taget="_blank" href="/search/%E8%BF%90%E7%AE%97/1.htm">运算</a><a class="tag" taget="_blank" href="/search/%E4%B9%98%E6%B3%95/1.htm">乘法</a> <div>  对于 JAVA 编程中,适当的采用位移运算,会减少代码的运行时间,提高项目的运行效率。这个可以从一道面试题说起:     问题: 用最有效率的方法算出2 乘以8 等於几?” 答案:2 << 3 由此就引发了我的思考,为什么位移运算会比乘法运算更快呢?其实简单的想想,计算机的内存是用由 0 和 1 组成的二</div> </li> <li><a href="/article/581.htm" title="java中的枚举(enmu)" target="_blank">java中的枚举(enmu)</a> <span class="text-muted">g21121</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a> <div>从jdk1.5开始,java增加了enum(枚举)这个类型,但是大家在平时运用中还是比较少用到枚举的,而且很多人和我一样对枚举一知半解,下面就跟大家一起学习下enmu枚举。先看一个最简单的枚举类型,一个返回类型的枚举: public enum ResultType { /** * 成功 */ SUCCESS, /** * 失败 */ FAIL, </div> </li> <li><a href="/article/708.htm" title="MQ初级学习" target="_blank">MQ初级学习</a> <span class="text-muted">510888780</span> <a class="tag" taget="_blank" href="/search/activemq/1.htm">activemq</a> <div>1.下载ActiveMQ 去官方网站下载:http://activemq.apache.org/ 2.运行ActiveMQ 解压缩apache-activemq-5.9.0-bin.zip到C盘,然后双击apache-activemq-5.9.0-\bin\activemq-admin.bat运行ActiveMQ程序。 启动ActiveMQ以后,登陆:http://localhos</div> </li> <li><a href="/article/835.htm" title="Spring_Transactional_Propagation" target="_blank">Spring_Transactional_Propagation</a> <span class="text-muted">布衣凌宇</span> <a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/transactional/1.htm">transactional</a> <div>//事务传播属性 @Transactional(propagation=Propagation.REQUIRED)//如果有事务,那么加入事务,没有的话新创建一个 @Transactional(propagation=Propagation.NOT_SUPPORTED)//这个方法不开启事务 @Transactional(propagation=Propagation.REQUIREDS_N</div> </li> <li><a href="/article/962.htm" title="我的spring学习笔记12-idref与ref的区别" target="_blank">我的spring学习笔记12-idref与ref的区别</a> <span class="text-muted">aijuans</span> <a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a> <div>idref用来将容器内其他bean的id传给<constructor-arg>/<property>元素,同时提供错误验证功能。例如: <bean id ="theTargetBean" class="..." /> <bean id ="theClientBean" class=&quo</div> </li> <li><a href="/article/1089.htm" title="Jqplot之折线图" target="_blank">Jqplot之折线图</a> <span class="text-muted">antlove</span> <a class="tag" taget="_blank" href="/search/js/1.htm">js</a><a class="tag" taget="_blank" href="/search/jquery/1.htm">jquery</a><a class="tag" taget="_blank" href="/search/Web/1.htm">Web</a><a class="tag" taget="_blank" href="/search/timeseries/1.htm">timeseries</a><a class="tag" taget="_blank" href="/search/jqplot/1.htm">jqplot</a> <div>timeseriesChart.html <script type="text/javascript" src="jslib/jquery.min.js"></script> <script type="text/javascript" src="jslib/excanvas.min.js&</div> </li> <li><a href="/article/1216.htm" title="JDBC中事务处理应用" target="_blank">JDBC中事务处理应用</a> <span class="text-muted">百合不是茶</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/JDBC%E7%BC%96%E7%A8%8B/1.htm">JDBC编程</a><a class="tag" taget="_blank" href="/search/%E4%BA%8B%E5%8A%A1%E6%8E%A7%E5%88%B6%E8%AF%AD%E5%8F%A5/1.htm">事务控制语句</a> <div>  解释事务的概念; 事务控制是sql语句中的核心之一;事务控制的作用就是保证数据的正常执行与异常之后可以恢复   事务常用命令:             Commit提交         </div> </li> <li><a href="/article/1343.htm" title="[转]ConcurrentHashMap Collections.synchronizedMap和Hashtable讨论" target="_blank">[转]ConcurrentHashMap Collections.synchronizedMap和Hashtable讨论</a> <span class="text-muted">bijian1013</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E5%A4%9A%E7%BA%BF%E7%A8%8B/1.htm">多线程</a><a class="tag" taget="_blank" href="/search/%E7%BA%BF%E7%A8%8B%E5%AE%89%E5%85%A8/1.htm">线程安全</a><a class="tag" taget="_blank" href="/search/HashMap/1.htm">HashMap</a> <div>在Java类库中出现的第一个关联的集合类是Hashtable,它是JDK1.0的一部分。 Hashtable提供了一种易于使用的、线程安全的、关联的map功能,这当然也是方便的。然而,线程安全性是凭代价换来的――Hashtable的所有方法都是同步的。此时,无竞争的同步会导致可观的性能代价。Hashtable的后继者HashMap是作为JDK1.2中的集合框架的一部分出现的,它通过提供一个不同步的</div> </li> <li><a href="/article/1470.htm" title="ng-if与ng-show、ng-hide指令的区别和注意事项" target="_blank">ng-if与ng-show、ng-hide指令的区别和注意事项</a> <span class="text-muted">bijian1013</span> <a class="tag" taget="_blank" href="/search/JavaScript/1.htm">JavaScript</a><a class="tag" taget="_blank" href="/search/AngularJS/1.htm">AngularJS</a> <div>        angularJS中的ng-show、ng-hide、ng-if指令都可以用来控制dom元素的显示或隐藏。ng-show和ng-hide根据所给表达式的值来显示或隐藏HTML元素。当赋值给ng-show指令的值为false时元素会被隐藏,值为true时元素会显示。ng-hide功能类似,使用方式相反。元素的显示或</div> </li> <li><a href="/article/1597.htm" title="【持久化框架MyBatis3七】MyBatis3定义typeHandler" target="_blank">【持久化框架MyBatis3七】MyBatis3定义typeHandler</a> <span class="text-muted">bit1129</span> <a class="tag" taget="_blank" href="/search/TypeHandler/1.htm">TypeHandler</a> <div>什么是typeHandler? typeHandler用于将某个类型的数据映射到表的某一列上,以完成MyBatis列跟某个属性的映射   内置typeHandler MyBatis内置了很多typeHandler,这写typeHandler通过org.apache.ibatis.type.TypeHandlerRegistry进行注册,比如对于日期型数据的typeHandler, </div> </li> <li><a href="/article/1724.htm" title="上传下载文件rz,sz命令" target="_blank">上传下载文件rz,sz命令</a> <span class="text-muted">bitcarter</span> <a class="tag" taget="_blank" href="/search/linux%E5%91%BD%E4%BB%A4rz/1.htm">linux命令rz</a> <div>刚开始使用rz上传和sz下载命令: 因为我们是通过secureCRT终端工具进行使用的所以会有上传下载这样的需求: 我遇到的问题: sz下载A文件10M左右,没有问题 但是将这个文件A再传到另一天服务器上时就出现传不上去,甚至出现乱码,死掉现象,具体问题 解决方法: 上传命令改为;rz -ybe 下载命令改为:sz -be filename 如果还是有问题: 那就是文</div> </li> <li><a href="/article/1851.htm" title="通过ngx-lua来统计nginx上的虚拟主机性能数据" target="_blank">通过ngx-lua来统计nginx上的虚拟主机性能数据</a> <span class="text-muted">ronin47</span> <a class="tag" taget="_blank" href="/search/ngx-lua%E3%80%80%E7%BB%9F%E8%AE%A1+%E8%A7%A3%E7%A6%81ip/1.htm">ngx-lua 统计 解禁ip</a> <div>介绍 以前我们为nginx做统计,都是通过对日志的分析来完成.比较麻烦,现在基于ngx_lua插件,开发了实时统计站点状态的脚本,解放生产力.项目主页: https://github.com/skyeydemon/ngx-lua-stats 功能 支持分不同虚拟主机统计, 同一个虚拟主机下可以分不同的location统计. 可以统计与query-times request-time </div> </li> <li><a href="/article/1978.htm" title="java-68-把数组排成最小的数。一个正整数数组,将它们连接起来排成一个数,输出能排出的所有数字中最小的。例如输入数组{32, 321},则输出32132" target="_blank">java-68-把数组排成最小的数。一个正整数数组,将它们连接起来排成一个数,输出能排出的所有数字中最小的。例如输入数组{32, 321},则输出32132</a> <span class="text-muted">bylijinnan</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a> <div> import java.util.Arrays; import java.util.Comparator; public class MinNumFromIntArray { /** * Q68输入一个正整数数组,将它们连接起来排成一个数,输出能排出的所有数字中最小的一个。 * 例如输入数组{32, 321},则输出这两个能排成的最小数字32132。请给出解决问题</div> </li> <li><a href="/article/2105.htm" title="Oracle基本操作" target="_blank">Oracle基本操作</a> <span class="text-muted">ccii</span> <a class="tag" taget="_blank" href="/search/Oracle+SQL%E6%80%BB%E7%BB%93/1.htm">Oracle SQL总结</a><a class="tag" taget="_blank" href="/search/Oracle+SQL%E8%AF%AD%E6%B3%95/1.htm">Oracle SQL语法</a><a class="tag" taget="_blank" href="/search/Oracle%E5%9F%BA%E6%9C%AC%E6%93%8D%E4%BD%9C/1.htm">Oracle基本操作</a><a class="tag" taget="_blank" href="/search/Oracle+SQL/1.htm">Oracle SQL</a> <div>一、表操作 1. 常用数据类型 NUMBER(p,s):可变长度的数字。p表示整数加小数的最大位数,s为最大小数位数。支持最大精度为38位 NVARCHAR2(size):变长字符串,最大长度为4000字节(以字符数为单位) VARCHAR2(size):变长字符串,最大长度为4000字节(以字节数为单位) CHAR(size):定长字符串,最大长度为2000字节,最小为1字节,默认</div> </li> <li><a href="/article/2232.htm" title="[强人工智能]实现强人工智能的路线图" target="_blank">[强人工智能]实现强人工智能的路线图</a> <span class="text-muted">comsci</span> <a class="tag" taget="_blank" href="/search/%E4%BA%BA%E5%B7%A5%E6%99%BA%E8%83%BD/1.htm">人工智能</a> <div>     1:创建一个用于记录拓扑网络连接的矩阵数据表      2:自动构造或者人工复制一个包含10万个连接(1000*1000)的流程图      3:将这个流程图导入到矩阵数据表中      4:在矩阵的每个有意义的节点中嵌入一段简单的</div> </li> <li><a href="/article/2359.htm" title="给Tomcat,Apache配置gzip压缩(HTTP压缩)功能" target="_blank">给Tomcat,Apache配置gzip压缩(HTTP压缩)功能</a> <span class="text-muted">cwqcwqmax9</span> <a class="tag" taget="_blank" href="/search/apache/1.htm">apache</a> <div>背景: HTTP 压缩可以大大提高浏览网站的速度,它的原理是,在客户端请求网页后,从服务器端将网页文件压缩,再下载到客户端,由客户端的浏览器负责解压缩并浏览。相对于普通的浏览过程HTML ,CSS,Javascript , Text ,它可以节省40%左右的流量。更为重要的是,它可以对动态生成的,包括CGI、PHP , JSP , ASP , Servlet,SHTML等输出的网页也能进行压缩,</div> </li> <li><a href="/article/2486.htm" title="SpringMVC and Struts2" target="_blank">SpringMVC and Struts2</a> <span class="text-muted">dashuaifu</span> <a class="tag" taget="_blank" href="/search/struts2/1.htm">struts2</a><a class="tag" taget="_blank" href="/search/springMVC/1.htm">springMVC</a> <div>SpringMVC VS Struts2 1: spring3开发效率高于struts 2: spring3 mvc可以认为已经100%零配置 3: struts2是类级别的拦截, 一个类对应一个request上下文, springmvc是方法级别的拦截,一个方法对应一个request上下文,而方法同时又跟一个url对应 所以说从架构本身上 spring3 mvc就容易实现r</div> </li> <li><a href="/article/2613.htm" title="windows常用命令行命令" target="_blank">windows常用命令行命令</a> <span class="text-muted">dcj3sjt126com</span> <a class="tag" taget="_blank" href="/search/windows/1.htm">windows</a><a class="tag" taget="_blank" href="/search/cmd/1.htm">cmd</a><a class="tag" taget="_blank" href="/search/command/1.htm">command</a> <div>在windows系统中,点击开始-运行,可以直接输入命令行,快速打开一些原本需要多次点击图标才能打开的界面,如常用的输入cmd打开dos命令行,输入taskmgr打开任务管理器。此处列出了网上搜集到的一些常用命令。winver 检查windows版本 wmimgmt.msc 打开windows管理体系结构(wmi) wupdmgr windows更新程序 wscrip</div> </li> <li><a href="/article/2740.htm" title="再看知名应用背后的第三方开源项目" target="_blank">再看知名应用背后的第三方开源项目</a> <span class="text-muted">dcj3sjt126com</span> <a class="tag" taget="_blank" href="/search/ios/1.htm">ios</a> <div>知名应用程序的设计和技术一直都是开发者需要学习的,同样这些应用所使用的开源框架也是不可忽视的一部分。此前《 iOS第三方开源库的吐槽和备忘》中作者ibireme列举了国内多款知名应用所使用的开源框架,并对其中一些框架进行了分析,同样国外开发者 @iOSCowboy也在博客中给我们列出了国外多款知名应用使用的开源框架。另外txx's blog中详细介绍了 Facebook Paper使用的第三</div> </li> <li><a href="/article/2867.htm" title="Objective-c单例模式的正确写法" target="_blank">Objective-c单例模式的正确写法</a> <span class="text-muted">jsntghf</span> <a class="tag" taget="_blank" href="/search/%E5%8D%95%E4%BE%8B/1.htm">单例</a><a class="tag" taget="_blank" href="/search/ios/1.htm">ios</a><a class="tag" taget="_blank" href="/search/iPhone/1.htm">iPhone</a> <div>一般情况下,可能我们写的单例模式是这样的: #import <Foundation/Foundation.h> @interface Downloader : NSObject + (instancetype)sharedDownloader; @end #import "Downloader.h" @implementation</div> </li> <li><a href="/article/2994.htm" title="jquery easyui datagrid 加载成功,选中某一行" target="_blank">jquery easyui datagrid 加载成功,选中某一行</a> <span class="text-muted">hae</span> <a class="tag" taget="_blank" href="/search/jquery/1.htm">jquery</a><a class="tag" taget="_blank" href="/search/easyui/1.htm">easyui</a><a class="tag" taget="_blank" href="/search/datagrid/1.htm">datagrid</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%8A%A0%E8%BD%BD/1.htm">数据加载</a> <div>1.首先你需要设置datagrid的onLoadSuccess $( '#dg' ).datagrid({onLoadSuccess :  function (data){      $( '#dg' ).datagrid( 'selectRow' ,3); }});   2.onL</div> </li> <li><a href="/article/3121.htm" title="jQuery用户数字打分评价效果" target="_blank">jQuery用户数字打分评价效果</a> <span class="text-muted">ini</span> <a class="tag" taget="_blank" href="/search/JavaScript/1.htm">JavaScript</a><a class="tag" taget="_blank" href="/search/html/1.htm">html</a><a class="tag" taget="_blank" href="/search/jquery/1.htm">jquery</a><a class="tag" taget="_blank" href="/search/Web/1.htm">Web</a><a class="tag" taget="_blank" href="/search/css/1.htm">css</a> <div>效果体验:http://hovertree.com/texiao/jquery/5.htmHTML文件代码: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>jQuery用户数字打分评分代码 - HoverTree</</div> </li> <li><a href="/article/3248.htm" title="mybatis的paramType" target="_blank">mybatis的paramType</a> <span class="text-muted">kerryg</span> <a class="tag" taget="_blank" href="/search/DAO/1.htm">DAO</a><a class="tag" taget="_blank" href="/search/sql/1.htm">sql</a> <div>MyBatis传多个参数: 1、采用#{0},#{1}获得参数:    Dao层函数方法:     public User selectUser(String name,String area); 对应的Mapper.xml    <select id="selectUser" result</div> </li> <li><a href="/article/3375.htm" title="centos 7安装mysql5.5" target="_blank">centos 7安装mysql5.5</a> <span class="text-muted">MrLee23</span> <a class="tag" taget="_blank" href="/search/centos/1.htm">centos</a> <div>首先centos7 已经不支持mysql,因为收费了你懂得,所以内部集成了mariadb,而安装mysql的话会和mariadb的文件冲突,所以需要先卸载掉mariadb,以下为卸载mariadb,安装mysql的步骤。   #列出所有被安装的rpm package rpm -qa | grep mariadb   #卸载 rpm -e mariadb-libs-5.</div> </li> <li><a href="/article/3502.htm" title="利用thrift来实现消息群发" target="_blank">利用thrift来实现消息群发</a> <span class="text-muted">qifeifei</span> <a class="tag" taget="_blank" href="/search/thrift/1.htm">thrift</a> <div>           Thrift项目一般用来做内部项目接偶用的,还有能跨不同语言的功能,非常方便,一般前端系统和后台server线上都是3个节点,然后前端通过获取client来访问后台server,那么如果是多太server,就是有一个负载均衡的方法,然后最后访问其中一个节点。那么换个思路,能不能发送给所有节点的server呢,如果能就</div> </li> <li><a href="/article/3629.htm" title="实现一个sizeof获取Java对象大小" target="_blank">实现一个sizeof获取Java对象大小</a> <span class="text-muted">teasp</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/HotSpot/1.htm">HotSpot</a><a class="tag" taget="_blank" href="/search/%E5%86%85%E5%AD%98/1.htm">内存</a><a class="tag" taget="_blank" href="/search/%E5%AF%B9%E8%B1%A1%E5%A4%A7%E5%B0%8F/1.htm">对象大小</a><a class="tag" taget="_blank" href="/search/sizeof/1.htm">sizeof</a> <div>   由于Java的设计者不想让程序员管理和了解内存的使用,我们想要知道一个对象在内存中的大小变得比较困难了。本文提供了可以获取对象的大小的方法,但是由于各个虚拟机在内存使用上可能存在不同,因此该方法不能在各虚拟机上都适用,而是仅在hotspot 32位虚拟机上,或者其它内存管理方式与hotspot 32位虚拟机相同的虚拟机上 适用。     </div> </li> <li><a href="/article/3756.htm" title="SVN错误及处理" target="_blank">SVN错误及处理</a> <span class="text-muted">xiangqian0505</span> <a class="tag" taget="_blank" href="/search/SVN%E6%8F%90%E4%BA%A4%E6%96%87%E4%BB%B6%E6%97%B6%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%BC%BA%E8%A1%8C%E5%85%B3%E9%97%AD/1.htm">SVN提交文件时服务器强行关闭</a> <div>在SVN服务控制台打开资源库“SVN无法读取current” ---摘自网络 写道 SVN无法读取current修复方法 Can't read file : End of file found 文件:repository/db/txn_current、repository/db/current   其中current记录当前最新版本号,txn_current记录版本库中版本</div> </li> </ul> </div> </div> </div> <div> <div class="container"> <div class="indexes"> <strong>按字母分类:</strong> <a href="/tags/A/1.htm" target="_blank">A</a><a href="/tags/B/1.htm" target="_blank">B</a><a href="/tags/C/1.htm" target="_blank">C</a><a href="/tags/D/1.htm" target="_blank">D</a><a href="/tags/E/1.htm" target="_blank">E</a><a href="/tags/F/1.htm" target="_blank">F</a><a href="/tags/G/1.htm" target="_blank">G</a><a href="/tags/H/1.htm" target="_blank">H</a><a href="/tags/I/1.htm" target="_blank">I</a><a href="/tags/J/1.htm" target="_blank">J</a><a href="/tags/K/1.htm" target="_blank">K</a><a href="/tags/L/1.htm" target="_blank">L</a><a href="/tags/M/1.htm" target="_blank">M</a><a href="/tags/N/1.htm" target="_blank">N</a><a href="/tags/O/1.htm" target="_blank">O</a><a href="/tags/P/1.htm" target="_blank">P</a><a href="/tags/Q/1.htm" target="_blank">Q</a><a href="/tags/R/1.htm" target="_blank">R</a><a href="/tags/S/1.htm" target="_blank">S</a><a href="/tags/T/1.htm" target="_blank">T</a><a href="/tags/U/1.htm" target="_blank">U</a><a href="/tags/V/1.htm" target="_blank">V</a><a href="/tags/W/1.htm" target="_blank">W</a><a href="/tags/X/1.htm" target="_blank">X</a><a href="/tags/Y/1.htm" target="_blank">Y</a><a href="/tags/Z/1.htm" target="_blank">Z</a><a href="/tags/0/1.htm" target="_blank">其他</a> </div> </div> </div> <footer id="footer" class="mb30 mt30"> <div class="container"> <div class="footBglm"> <a target="_blank" href="/">首页</a> - <a target="_blank" href="/custom/about.htm">关于我们</a> - <a target="_blank" href="/search/Java/1.htm">站内搜索</a> - <a target="_blank" href="/sitemap.txt">Sitemap</a> - <a target="_blank" href="/custom/delete.htm">侵权投诉</a> </div> <div class="copyright">版权所有 IT知识库 CopyRight © 2000-2050 E-COM-NET.COM , All Rights Reserved. <!-- <a href="https://beian.miit.gov.cn/" rel="nofollow" target="_blank">京ICP备09083238号</a><br>--> </div> </div> </footer> <!-- 代码高亮 --> <script type="text/javascript" src="/static/syntaxhighlighter/scripts/shCore.js"></script> <script type="text/javascript" src="/static/syntaxhighlighter/scripts/shLegacy.js"></script> <script type="text/javascript" src="/static/syntaxhighlighter/scripts/shAutoloader.js"></script> <link type="text/css" rel="stylesheet" href="/static/syntaxhighlighter/styles/shCoreDefault.css"/> <script type="text/javascript" src="/static/syntaxhighlighter/src/my_start_1.js"></script> </body> </html>