Jasperreport"

From Documentation
 
(36 intermediate revisions by 10 users not shown)
Line 3: Line 3:
 
= Jasperreport =
 
= Jasperreport =
  
*Demonstration: [http://www.zkoss.org/zkdemo/userguide/#d3 Jasperreport]
+
*Demonstration: [http://www.zkoss.org/zkdemo/reporting/jasperreport Jasperreport]
 
*Java API: <javadoc>org.zkoss.zkex.zul.Jasperreport</javadoc>
 
*Java API: <javadoc>org.zkoss.zkex.zul.Jasperreport</javadoc>
 
*JavaScript API: <javadoc directory="jsdoc">zkex.utl.Jasperreport</javadoc>
 
*JavaScript API: <javadoc directory="jsdoc">zkex.utl.Jasperreport</javadoc>
 +
*Style Guide: N/A
 +
*{{ZK PE and EE}}
  
 
= Employment/Purpose =
 
= Employment/Purpose =
The JasperReport component. It is used to generate a Jasper report into an inline frame
 
  
 +
The JasperReport component is based on a 3rd party JasperReports Library, a report generator (e.g. XML generator, PDF generator etc.). This component is used to generate a Jasper report into an inline frame.
  
 +
= Including Dependency =
 +
 +
{{versionSince| 9.6.0}}
 +
ZK doesn't include jasperreports by default. If you need to use this component, you have to include the dependency manually like:
 +
 +
<syntaxhighlight lang='xml'>
 +
<dependency>
 +
<groupId>net.sf.jasperreports</groupId>
 +
<artifactId>jasperreports</artifactId>
 +
<version>6.17.0</version>
 +
</dependency>
 +
</syntaxhighlight>
 +
 +
== 3rd Party Vulnerability Notice ==
 +
Jasperreport uses another external library called itext 2, and there are [https://security.snyk.io/package/maven/org.bouncycastle:bcprov-jdk15on some vulnerabilities] reported on <code>org.bouncycastle:bcprov-jdk15on</code>, which is a dependency of itext 2. If you are concerned, you can exclude that dependency, it does not affect the use or the PDF exporting of this component. Alternatively, Jasperreport does provide a separate PDF Exporter with a newer version of itext which does not contain the affected bouncycastle lib. For more information, please check [https://github.com/Jaspersoft/jasperreports-pdf-lib7 JasperReports PDF Exporter Lib Seven].
  
 
= Example =
 
= Example =
Line 27: Line 44:
 
parameters.put("DataFile", "CustomDataSource from java");
 
parameters.put("DataFile", "CustomDataSource from java");
 
 
report.setSrc("/userguide/data/jasperreport.jasper");
+
report.setSrc("/data/jasperreport.jasper");
 
report.setParameters(parameters);
 
report.setParameters(parameters);
 
report.setDatasource(new CustomDataSource());
 
report.setDatasource(new CustomDataSource());
Line 34: Line 51:
 
</source>
 
</source>
  
=Supported events=
 
  
{| border="1" | width="100%"
+
 
 +
== Provide Export Parameters ==
 +
The Jasperreport component API provides a way to specify export parameters. To do so, you should put a Map containing export parameters within the parameters Map, with key <code>"exportParameter"</code>. For example:
 +
 
 +
<source lang="java">
 +
Map parameters = new HashMap();
 +
Map exportParams = new HashMap();
 +
exportParams.put("net.sf.jasperreports.export.mypropertyname", true);
 +
parameters.put("exportParameter", exportParams);
 +
report.setParameters(parameters); // report is the Jasperreport component
 +
</source>
 +
 
 +
=== One-Page-Per-Sheet Property ===
 +
In Jasperreport engine, this property is default to be false. However, the default behavior is turned on in the Jasperreport component, in which case when the report is exported as Excel format there will be one sheet generated for each page. To override this setting, set it as an export parameter as the following:
 +
 
 +
<source lang="java">
 +
Map parameters = new HashMap();
 +
Map exportParams = new HashMap();
 +
exportParams.put(JRXlsAbstractExporterParameter.PROPERTY_ONE_PAGE_PER_SHEET.toString(), false);
 +
parameters.put("exportParameter", exportParams);
 +
report.setParameters(parameters); // report is the Jasperreport component
 +
</source>
 +
 
 +
= exportName =
 +
{{versionSince| 8.6.1}}
 +
 
 +
You can specify the export file name for the download if any, the full file name will be exportName + "." + format.
 +
 
 +
Note: exportName can not be empty or null.
 +
 
 +
Default: "report"
 +
 
 +
<source lang="xml">
 +
<jasperreport exportName="test"/>
 +
</source>
 +
 
 +
=Supported Events=
 +
 
 +
{| class='wikitable' | width="100%"
 
! <center>Name</center>
 
! <center>Name</center>
 
! <center>Event Type</center>
 
! <center>Event Type</center>
Line 43: Line 97:
 
| None
 
| None
 
|}
 
|}
 +
 +
*Inherited Supported Events: [[ZK_Component_Reference/Essential_Components/Iframe#Supported_Events | Iframe]]
  
 
=Supported Children=
 
=Supported Children=
Line 48: Line 104:
 
  *NONE
 
  *NONE
  
=Use cases=
+
=Supported Type=
 +
 
 +
== Usage ==
 +
 
 +
===Java Code===
 +
<source lang="java" >
 +
//Jasperreport report;
 +
report.setType("pdf"); // report is the Jasperreport component
 +
</source>
 +
 
 +
===Zul Code===
 +
<source lang="xml" >
 +
<jasperreport id="report" type="pdf" />
 +
</source>
 +
 
 +
== Type List ==
 +
{| class='wikitable' | width="100%"
 +
! Type !! Version
 +
|-
 +
| pdf
 +
|
 +
|-
 +
| xml
 +
|
 +
|-
 +
| html
 +
|
 +
|-
 +
| rtf
 +
|
 +
|-
 +
| xls
 +
|
 +
|-
 +
| jxl
 +
|
 +
|-
 +
| csv
 +
|
 +
|-
 +
| odt
 +
|
 +
|-
 +
| xlsx
 +
| {{versionSince| 5.0.8}}
 +
|-
 +
| docx
 +
| {{versionSince| 5.0.8}}
 +
|-
 +
| graphic2d
 +
| {{versionSince| 5.0.8}}
 +
|-
 +
| ods
 +
| {{versionSince| 5.0.8}}
 +
|-
 +
| pptx
 +
| {{versionSince| 5.0.8}}
 +
|-
 +
| txt
 +
| {{versionSince| 5.0.8}}
 +
|-
 +
| xhtml
 +
| {{versionSince| 5.0.8}}
 +
|}
 +
 
 +
= Supported JasperReport Version =
 +
{| class='wikitable' | width="100%"
 +
! ZK !! JasperReport !! Transitive Dependency
 +
|-
 +
| 9.6.0
 +
| 6.14.0
 +
| optional ([https://mvnrepository.com/artifact/net.sf.jasperreports/jasperreports net.sf.jasperreports:jasperreports] needs to be added manually on demand)
 +
|-
 +
| 9.5.0
 +
| 6.14.0
 +
| added by default
 +
|-
 +
| 9.0.0
 +
| 6.6.0
 +
| added by default
 +
|-
 +
| 8.6.0
 +
| 6.5.1
 +
| added by default
 +
|-
 +
| 7.0.0
 +
| 4.5.1
 +
| added by default
 +
|-
 +
| 6.0.0
 +
| 4.0.1
 +
| added by default
 +
|}
  
{| border='1px' | width="100%"
+
=Use Cases=
! Version !! Description !! Example Location
+
 
 +
{| class='wikitable' | width="100%"
 +
! Version !! Description  
 
|-
 
|-
 
| 5.0.2
 
| 5.0.2
| How to use Dynamic Jasper Reports
+
| [http://www.zkoss.org/forum/listComment/10873 How to use Dynamic Jasper Reports]
| http://www.zkoss.org/forum/listComment/10873
+
|-
 +
| 6/5.0.8
 +
| [http://books.zkoss.org/wiki/Small_Talks/2012/April/Create_a_Report_with_ZK_using_iReport_and_JasperReports Create a Report with ZK using iReport and JasperReports]
 
|}
 
|}
 +
 +
=Troubleshooting=
 +
 +
== Linux ==
 +
Jasperreport depends on the fonts you use in the report. For more information, please  refer to [[ZK Installation Guide/Setting up OS/Linux|ZK Installation  Guide: Linux]].
  
 
=Version History=
 
=Version History=
  
{| border='1px' | width="100%"
+
{| class='wikitable' | width="100%"
 
! Version !! Date !! Content
 
! Version !! Date !! Content
 
|-
 
|-
| &nbsp;
+
| 5.0.1
| &nbsp;
+
| March 2010
| &nbsp;
+
| Support Hibernate and SQL connections
 +
|-
 +
| 5.0.8
 +
| Upgrade JaserReport version to 4.0 and support new JasperReport exporter
 +
|
 
|}
 
|}
  
 
{{ZKComponentReferencePageFooter}}
 
{{ZKComponentReferencePageFooter}}

Latest revision as of 03:38, 13 January 2023

Jasperreport

Employment/Purpose

The JasperReport component is based on a 3rd party JasperReports Library, a report generator (e.g. XML generator, PDF generator etc.). This component is used to generate a Jasper report into an inline frame.

Including Dependency

Since 9.6.0 ZK doesn't include jasperreports by default. If you need to use this component, you have to include the dependency manually like:

<dependency>
	<groupId>net.sf.jasperreports</groupId>
	<artifactId>jasperreports</artifactId>
	<version>6.17.0</version>
</dependency>

3rd Party Vulnerability Notice

Jasperreport uses another external library called itext 2, and there are some vulnerabilities reported on org.bouncycastle:bcprov-jdk15on, which is a dependency of itext 2. If you are concerned, you can exclude that dependency, it does not affect the use or the PDF exporting of this component. Alternatively, Jasperreport does provide a separate PDF Exporter with a newer version of itext which does not contain the affected bouncycastle lib. For more information, please check JasperReports PDF Exporter Lib Seven.

Example

ZKComRef Jasperreport Examples.PNG

	<jasperreport id="report" height="360px" />
	
	<zscript>
		import org.zkoss.zkdemo.userguide.CustomDataSource;
		
			//Preparing parameters
			Map parameters = new HashMap();
			parameters.put("ReportTitle", "Address Report");
			parameters.put("DataFile", "CustomDataSource from java");
			
			report.setSrc("/data/jasperreport.jasper");
			report.setParameters(parameters);
			report.setDatasource(new CustomDataSource());
			report.setType("pdf");
	</zscript>


Provide Export Parameters

The Jasperreport component API provides a way to specify export parameters. To do so, you should put a Map containing export parameters within the parameters Map, with key "exportParameter". For example:

	Map parameters = new HashMap();
	Map exportParams = new HashMap();
	exportParams.put("net.sf.jasperreports.export.mypropertyname", true);
	parameters.put("exportParameter", exportParams);
	report.setParameters(parameters); // report is the Jasperreport component

One-Page-Per-Sheet Property

In Jasperreport engine, this property is default to be false. However, the default behavior is turned on in the Jasperreport component, in which case when the report is exported as Excel format there will be one sheet generated for each page. To override this setting, set it as an export parameter as the following:

	Map parameters = new HashMap();
	Map exportParams = new HashMap();
	exportParams.put(JRXlsAbstractExporterParameter.PROPERTY_ONE_PAGE_PER_SHEET.toString(), false);
	parameters.put("exportParameter", exportParams);
	report.setParameters(parameters); // report is the Jasperreport component

exportName

Since 8.6.1

You can specify the export file name for the download if any, the full file name will be exportName + "." + format.

Note: exportName can not be empty or null.

Default: "report"

<jasperreport exportName="test"/>

Supported Events

Name
Event Type
None None

Supported Children

*NONE

Supported Type

Usage

Java Code

//Jasperreport report;
report.setType("pdf"); // report is the Jasperreport component

Zul Code

<jasperreport id="report" type="pdf" />

Type List

Type Version
pdf
xml
html
rtf
xls
jxl
csv
odt
xlsx Since 5.0.8
docx Since 5.0.8
graphic2d Since 5.0.8
ods Since 5.0.8
pptx Since 5.0.8
txt Since 5.0.8
xhtml Since 5.0.8

Supported JasperReport Version

ZK JasperReport Transitive Dependency
9.6.0 6.14.0 optional (net.sf.jasperreports:jasperreports needs to be added manually on demand)
9.5.0 6.14.0 added by default
9.0.0 6.6.0 added by default
8.6.0 6.5.1 added by default
7.0.0 4.5.1 added by default
6.0.0 4.0.1 added by default

Use Cases

Version Description
5.0.2 How to use Dynamic Jasper Reports
6/5.0.8 Create a Report with ZK using iReport and JasperReports

Troubleshooting

Linux

Jasperreport depends on the fonts you use in the report. For more information, please refer to ZK Installation Guide: Linux.

Version History

Version Date Content
5.0.1 March 2010 Support Hibernate and SQL connections
5.0.8 Upgrade JaserReport version to 4.0 and support new JasperReport exporter



Last Update : 2023/01/13

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.