Jasper iReport

Jasper iReport

Here I am describing on Jasper iReport and showing some important features of iReport. My another post has described how to create a report using Jasper iReport and how to execute that report by eclipse java project.

What is Jasper iReport

To see Jasper iReport home page, please click here. Yet, I have described another post on it. Here I am gonna show you how to create a report using Jasper iReport.

Jasper iReport : Create a report using iReport

Steps:

# set ClassPath: put your desire database driver jar file into the lib folder of iReport. you can do that Options->class path-> add jar

# Element:

-Static text is used Label and Text field is used for Value.

-Bar Code tools is used for print bar code. Jasper iReport - barcode make sure the font has to select that you are going to use for printing the barcode. to set font for bar code right click on bar code element and select properties and select BarCode tab and set the appropiate type that is font.

-SubReport: this is very important element of Jasper iReport. Jasper iReport - master-details it is mostly used, when you need a master details report. For example,  an itemlist according to category. A report that header portion shows the category details and also show all the items of that category. you can show all the categories group by one paritcular field among category’s details. that time you have to select that field as group by. like ‘Category A’ shows the details of category at the header and body show all the item of ‘Category A’. so this item list of ‘Category A’ is the sub report. for grouping of any category description fileds you have to select that filed group by. to do you have to select that field on right boutton click and select Group selected items.

– Field, Variable & Parameter: We can create variable which will only used as variable, denoted as $V{name}, that scope is the whole report. Field,denoted as $F{name}, that is used for showing a field in the report.Parameter ,denoted as $P{name}, that takes data from java class or master report to subreport.

-Connections/Data Sources: This is the way from where you feed the data to your report. Most common Connection is JDBC connection, you can used this connection for connecting your RDMS Database. Jasper iReport supports most of popular database like Oracle, MySql, MsSql, PostGresql, MSAccess… etc. You can also used XML data source that time you have to select the xml file as a data source. JavaBeans source is suppose your program class file List contains some data, such case report grabbed data from that list. Jasper iReport is really awesome tools. Hibernate Connection is HQL database connection. lets say how you do that, here I described how make your data source as XML datasource, click Data->Connections/DataSources->New->XML file data source -> Next ->Select the xml file. and choose Use the report Xpath, click the test button for confirmation of your datasource connection. if your xml file has master details data like

<Category name=”A” noOfItem=2>

<Item sku=”2322″ productName=”Poland Spring Water”/>

….

</Category>

lets set the datasource in the Report Query.

For masters, Category details, click Data->Report Query select Report Query tab, Query Language: XPath, Query: //Category click the Read Fields button then all the fields of Category will shows.

For sub-report, Item list,  open subreport & click Data->Report Query select Report Query Jasper iReport - reportquery1tab, Query Language: XPath, Query: /Category/Item click the Read Fields button then all the fields of Category will shows.

# Some common error:

1.if Jasper iReport shows casting error so it means it cant convert to desire type to actual type. for example – the text field type is Double and xml data is String such this case we can set the expression as: new Double($F{price}).

2.Boolean converting error. suppose reprot has Sex field and textfiled type is boolean but xml data is like that – sex=”0″ so it will generate error. if we want to show Male/Female or conditionally show a value, do follows this step. change the text file type is java.lang.String and edit Expression as

( $F{sex}.equals(“0”) ? “Male” : “Female”)

# Band: Jasper iReport breaks the report by several bands. we define the band as section or portion of whole report. this is as a good features. you can design as you want. if you want to show the title just set the title band hight value or not set the hieght value is zero, event we can show it conditionally if i used Print when expresstion value. if we used group by for a particular filed then we will get that Column Header and footer so that we can show the some summary information of the group. If there is no data so we can show this information using noData Band.

Another topic, if you want move more element, shift+click for selection and slow move use arrow , fast move use shift+arrow.

One thought on “Jasper iReport

  1. Dear Sir,

    Your material is good. I can export the file in excel (.xls) format.

    The code is

    response.setContentType(“application/xls”);
    response.setHeader(“Content-Disposition”, “inline; filename=””+purchaseId+”.xls””);
    exporter = new JRXlsExporter();
    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
    exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);

    This war file can be deployed in linux – centos.

    My question is the file is exported and blank xls is displayed and formula is not displayed in the xls sheet.

    for eg., x1 =10; y1=10 z1=x1*y1
    I can set the formula field in z1. I can get the values of 100, but not the formula.

    Please guide on this issue.

    Thanks & regards

    Siva N P

Leave a Reply

Your email address will not be published. Required fields are marked *