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


Monday 27 May 2013

Starting with java

Starting with java

Hi Friends.
This post is for those who want to learn java from Starting . The article help you to find that how one can easily learn java . All he/she need to have patience and motivation to learn. I will not tell you the definition's , becoz these are already on Internet .
I will tell you how java is install in one's system and start coding in java.To code in java we need to install java in our system

Download link for java -  http://www.oracle.com/technetwork/java/javase/downloads/index.html

Download from above link according to your system requirement (like system 32(x86)bit and 64bit) and download the exe by accepting the agreement.

Steps to install on windows.

1-click on exe and install in OS drive that is C drive of your system

2-After installation Set the Environment variable of your system by right click on My computer --> properties --> Advance System setting --> Environment variables --> System varaibles --> path

















3- Now apply changes and go to cmd and type java














4- if this appears in your screen (then congratulation java is installed on yous system )
if not then see the steps and snapshot again .