Showing posts with label IREPORT. Show all posts
Showing posts with label IREPORT. Show all posts

Tuesday, 4 June 2013

iReport

                                                                     iReport

Report Inspector –
  

Parameters- these are the parameters which we send from outside the report like (in case of java we send them as Hash map parameters) , there value remain same throughout the report.

Fields-  These are fields which are defined as same name as in DATABASE COLOUMN or DATASOURCE object fields. They are generally used in DETAIL band of reports and repeat there value according to the list provide in datasource or column row in database.

Variable – these are same as programming variable but only change is, we can change there value in variable expression.

Title BAND – Used for report title , Appear once in report life cycle

Page Header BAND – Used to write page header, appear on every page of report.

Column Header – Appear top of every column in detail band. detail fields are exactly same left as static text of column headers.

Detail BAND- Fields which are in this once repeated itself for all the values.

Summary BAND- at last of report content of this band is printed.


NO DATA BAND – When no datasource is available no data band is printed only if report setting property for no data is no data band.

Friday, 31 May 2013

Jasper Report's Using Spring MVC

Today we gone make Jasper report's using Java Spring MVC application

The Steps to make report are as follows -:

1- Design a Report with empty datasource using iReport as described in previuos post check on following link -  starting-with-netbeans-ireport.html

  In Same select empty datasource and make feild with same name as in your application bean class(if don't get this line you will get it later just follow the steps)

2- Make Jasper  generated by compiling(preview button on iReport) or jrxml that obtail before compiling the design  on design in iReport.

check and try to understand this image given




3- Now we have jasper or jrxml file how to use it in our code, But first where we should get Jar file for Jasper Reports




Jar Address in your system if iReport is installed in you system then go to the folder of iReport which is in default path is

C:\Program Files (x86)\Jaspersoft\iReport-5.0.4\ireport\modules\ext \




4- Now make a Simple spring mvc project in eclipse or IDE suit's you



In that project make a POJO class like this

for example --




class person

{

String name;

String address;

String dob;

Long phone;

****************************

Getter and setter for same

****************************




}




5- Intilize these Person POJO object's with content from database or hardcoded and assign to

List<person> object

6-this list object act as and Datasource for your reports, Now how we provide this datasource to or reports

this we done in our java code so hold your breath.




7- Now code for you controller is



{ Inside your controller method which is called on your click of any link

******************************************************************************* List<person> personlist=datasource // Told earlier in point 5
try {



// 1. Add report parameters
HashMap<String, Object> parametrs= new HashMap<String, Object>();
parametrs.put("Title", "User Report");

// 2. Retrieve template
InputStream reportStream = this.getClass().getResourceAsStream(TEMPLATEPATH.jrxml);

// 3. Convert template to JasperDesign
JasperDesign jd = JRXmlLoader.load(reportStream);

// 4. Compile design to JasperReport
JasperReport jr = JasperCompileManager.compileReport(jd);

// 5. Create the JasperPrint object
// Make sure to pass the JasperReport, report parameters, and data source

JasperPrint jp = JasperFillManager.fillReport(jr, parametrs, personlist);



// Set our response properties
// Here you can declare a custom filename

String fileName = "UserReport.pdf";
response.setHeader("Content-Disposition", "inline; filename="+ fileName);

// Set content type
response.setContentType(MEDIA_TYPE_PDF);


// Export is most important part of reports
JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, response.outputstream());
exporter.exportReport();



return null;

}


*********************************************************************************

We can directly use Jasper file in reportstream to skip compilation step as it can also be done by iReport designer


code is ---

InputStream reportStream = this.getClass().getResourceAsStream(TEMPLATEPATH.jasper);

JasperPrint jp = JasperFillManager.fillReport(reportStream , parametrs, personlist);
down steps of code are same as in above


********************************************************************************


NOTE - check in you report design that fields name are same as in POJO class

Have great programming :)
  

Wednesday, 29 May 2013

STARTING WITH NETBEANS IREPORT

Hi friends in today's post , I will tell you about netbeans ireport , How it work , how we start to make Reports with it.

iReport is an netbeans ide, that is used to design report templets or reports , It uses JasperReports API for making reports . In iReport we can design report template and make numbers of reports based on different data inputs.
The main benefits of using  iReport is :-
  1. Simple Designing of reports .
  2. Output in different format like excel,pdf,doc,docx etc. 
  3. Pictorial reports are easy to made
 
You can easy download iReport from this URL -http://sourceforge.net/projects/ireport/files/iReport/iReport-5.0.0/





Now There is Simple Steps to make your First Report Using iReport

Note - Use MySql database in this tutorial

1.make the Sql connection and follow the Guided steps




2- Fill the mysql connection and test it.

3-Create a new report by clicking on File-->New




















4- open the template and A4 and click on show picture button



5- write sql query to retrieve fields from your db


6- Press ok and you can see the all coloumn names under Feilds section of report inspector, Now drag feilds in detail band as show in images



7- click on preview and see your reports


I will discuss more about iReport in next post's Thanks and best of luck