Archive

Archive for the ‘JasperReports’ Category

JasperReports 3.6 Development Cookbook

January 6, 2011 Leave a comment

I am one of the reviewers of this book.

JasperReports 3.6 Development Cookbook

JasperReports 3.6 Development Cookbook - Credits Page

It is really good book.

Categories: JasperReports Tags:

Reports: Jasper Vs Apache POI Excel

September 7, 2010 2 comments

After working with Jasper Reports….these are the points to remember while designing the reports.

1. Go for Jasper, only if it is required. Other wise better to use Apache POI Excel

Generally PDFs are read only. It is good to print invoices, bills, receipts, …etc

When there is a report with 40 pages, who is having time to print and read it.

If we use Apache POI  to write data to excel, it is easy to filter the data and do more drill down offline.

—————————————–

It is very difficult to format the report in Jasper Reports. It is easy to do in Excel.

—————————————–

We can off load the business logic to Excel and do in macros. This reduces burden on server side.

We can’t do in PDFs.

—————————————–

We can provide templates in Excel and we can import the data back from supervisor from a trip.

We can’t do this in PDFs.

—————————————–

Conclusion: User Jasper Reports, only if it is required. Other wise easy to complete same stuff with Apache POI Excel API.

—————————————–

Problem with Apache POI Excel API, client’s must need to have Windows and MS Office to read the documents.

—————————————–

Also better to use http://www.displaytag.sf.net to show data in tabular view.
1. user can sort the data easily.
2. Easy to provide reports in footer.

Jasper Reports 3.7.3, JBoss 4.2.3, Java 1.6.21 upgrade Problem

July 15, 2010 Leave a comment

Problem: When upgrading to Jasper Reports 3.7.3, JBoss 4.2.3, Java 1.6.21 upgrade Problem, got the following problem.

org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/classes/application-context.xml]; nested exception is java.lang.ClassCastException: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl cannot be cast to javax.xml.parsers.DocumentBuilderFactory
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:420)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)

Solution: XML Parser is provided by JBoss and Java 1.6. Due to this we need to knock down it from deployment

<dependency>
    <groupId>net.sf.jasperreports</groupId>
    <artifactId>jasperreports</artifactId>
    <version>3.7.3</version>
	<exclusions>
		<exclusion>  
			<groupId>xml-apis</groupId>
			<artifactId>xml-apis</artifactId>
		</exclusion>
	</exclusions> 
</dependency>

Jasper Reports – Pie Chart Shadows

May 13, 2010 Leave a comment

Problem: Getting ugly shadows around tiny pie charts.

Solution: In palette select Theme as “aegean”

We will get this following error

Caused by: net.sf.jasperreports.engine.JRRuntimeException: Chart theme ‘aegean’ not found.

We need to add to the pom file.
jasperreports-chart-themes-3.6.x.jar
castor-1.2.jar
spring-core-2.5.5.jar
spring-beans-2.5.5.jar

Maven is not pulling them from repository.
We need to install.

Note: Try to use the files comes with respective jar bundle. Otherwise we will get version related errors.

Jasper Reports Public Repository

May 13, 2010 Leave a comment

Many of the public maven repositories dont have support for latest Jasper Reports.

Add the following to pom.xml file.

<repositories>
      <repository>
        <id>jasperreports</id>
        <url>http://jasperreports.sourceforge.net/maven2</url>
      </repository>
 </repositories>

Problems: Still it wont download themes and fonts jars.

Restlet – Read HTTP Headers

March 4, 2010 Leave a comment

Problem: How to read HTTP Headers in Restlet? Also we need to get Date from HTTP Headers.

Series<Parameter> headers = (Series<Parameter>) getRequest().getAttributes().get("org.restlet.http.headers");
Set<String> headerNames = headers.getNames();
for(String headerName:headerNames)
{
	System.out.println( "name==>"+headerName+" value==>"+ headers.getFirstValue(headerName));
}

Output:

name==>accept-encoding value==>gzip,deflate
name==>connection value==>keep-alive
name==>accept-language value==>en-us,en;q=0.5
name==>host value==>localhost:8080
name==>accept-charset value==>ISO-8859-1,utf-8;q=0.7,*;q=0.7
name==>user-agent value==>Mozilla/5.0 (Windows; U; Windows NT 4.x; en-US; rv:1.x.x.x) Gecko/23423423 Firefox/2.4.6
name==>accept value==>text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
name==>keep-alive value==>300

Observation: Date is missing when tried from Browser.
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

When tried from Restlet Client, it is working.

Form attributes = new Form();  
attributes.add( "message.date", "Mar-03-2010 10:30 AM" );
request.getAttributes().put( "org.restlet.http.headers", attributes );

Final Solution:
It is difficult to depend on HTTP Headers when clients are from Flex and other applications.
Easiest way is add Query String parameter like &date=123123123123123

Reference:
http://www.restlet.org/documentation/1.0/faq
http://wiki.restlet.org/docs_2.0/13-restlet/27-restlet/130-restlet.html
http://en.wikipedia.org/wiki/List_of_HTTP_headers

Setting JasperReports document properties

March 1, 2010 Leave a comment

Problem Statement:  How to set JasperReports document properties?

Solution:

net.sf.jasperreports.engine.JRExporter exporter = new net.sf.jasperreports.engine.export.JRPdfExporter();
// Properties Begin
exporter.setParameter( JRPdfExporterParameter.METADATA_TITLE, "Title of the Document" );
exporter.setParameter( JRPdfExporterParameter.METADATA_AUTHOR, "Author of the document" );
exporter.setParameter( JRPdfExporterParameter.METADATA_SUBJECT, "Subject line of document" );
exporter.setParameter( JRPdfExporterParameter.METADATA_KEYWORDS, "Key Words to search down the line" );
exporter.setParameter( JRPdfExporterParameter.METADATA_CREATOR, "Application Name, which created this document." );
exporter.setParameter( JRPdfExporterParameter.OUTPUT_FILE_NAME, "Used when click on save button from client" );


//This used to set document passwords and compression and encryption
JRProperties.setProperty( JRPdfExporterParameter.PROPERTY_USER_PASSWORD, "password1" );
JRProperties.setProperty( JRPdfExporterParameter.PROPERTY_OWNER_PASSWORD, "password2" );
JRProperties.setProperty( JRPdfExporterParameter.PROPERTY_ENCRYPTED, true );
JRProperties.setProperty( JRPdfExporterParameter.PROPERTY_COMPRESSED, true );


ByteArrayOutputStream out  = new ByteArrayOutputStream();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, out);
exporter.exportReport();

Reference: Check
1. Jasper Reports API: http://jasperreports.sourceforge.net/api/index.html
2. Jasper Reports Forum
3. Samples: http://jasperforge.org/uploads/publish/jasperreportswebsite/trunk/samples.html

-o-

JasperReports – conditionalStyle

February 23, 2010 Leave a comment

Problem: How to add colors based on project Status?
Like complete – Green, notcomplete – Red, other – None

Solution: Need to use conditionalStyle

<style name="style_name1" 
	isDefault="false" 
	forecolor="#000000" 
	backcolor="#FFFFFF" 
	fontName="Arial" 
	pdfFontName="Helvetica"
	fontSize="8">
	<conditionalStyle>
		<conditionExpression><![CDATA[new Boolean ($F{projectStatus}.equals("complete"))]]></conditionExpression>
		<style forecolor="#008B45" />
	</conditionalStyle>
	<conditionalStyle>
		<conditionExpression><![CDATA[new Boolean ($F{projectStatus}.equals("notcomplete"))]]></conditionExpression>
		<style forecolor="#FF0000" />
	</conditionalStyle>
	<conditionalStyle>
		<conditionExpression><![CDATA[new Boolean ($F{projectStatus}.equals("other"))]]></conditionExpression>
		<style/>
	</conditionalStyle>
</style>

Reference:

CSS Colors Chart : http://www.somacon.com/p142.php
Style Generator for Jasper: http://www.langtags.com/xmlsnippets/jasperreport/style.html

JasperReports – Style

February 23, 2010 Leave a comment

Problem: How to prepare style for Jasper Report Elements?

Style Generator http://www.langtags.com/xmlsnippets/jasperreport/style.html

JasperReports UI Tools

Jasper Assistant http://www.jasperassistant.com/
iReport http://jasperforge.org/projects/ireport

JasperReports – Image Loading Static Vs Dynamic

February 23, 2010 Leave a comment

Problem: How to load images in JasperReports?

This is the best way to refer static images.

<imageExpression class="java.lang.String"><![CDATA["images/image1.jpg"]]>  

Images must be in the class path. We can pass this value through variable too.

This is the best way to load dynamic images.
Which means that we want to manipulate images based on runtime logic.

<imageExpression class="java.awt.Image"><![CDATA[$F{dynamicImageName}]]>

These images can be picked up from class path or manipulated in memory during run time.
Example: Graphs, Pie Charts …etc

Follow

Get every new post delivered to your Inbox.