Wednesday, April 18, 2012

Calling Java Methods From Jasper Reports


To call java methods from jasper reports. Just Follow the following steps

Step1:

create a java class with a static method which return something i.e either String or Integer.. etc

Step2:

Create a jar file by the following command 
jar - cvf file.jar packagename

Step3:

set it as class path as 
Tools > Options > ClassPath > Add Jar > Ok

Step4: 

Create a Static field. Edit its Expression by EditExpression to  "new packagename.classname().methodname(parameter) "
Step5:
Place this static field wherever you want

Tuesday, April 10, 2012

jasper reports- creating and compiling basic jasper report without any data from jsp or servlets

I have designed a report in ireport of jasper report .To compile and execute that report we have to place the following jar files into lib folder of our WEB-INF folder

Jar file Names:

1. commons-collections-3.2.1.jar
2. commons-beanutils-1.8.2.jar
3. commons-digester.1.7.jar
4. jasperreports-4.5.0.jar
5. commons-logging-1.1.1.jar
6. itext2.1.7.jar
7. asm-3.3.jar
8. antlworks-1.4.3.jar
9. servlet-api.jar
10. groovy-all-1.7.jar

These are the common jar files required.

Write a Servlet  that generates PDF report from out compiled jasper report. The servlet code of a demo servlet is shown below . Please ffollow the code....

code: 

 HashMap hm = null;
    
      String jrxmlFileName = getServletContext().getRealPath("\\jrxml")+"\\demoreport.jrxml";
     
   String jasperFileName =getServletContext().getRealPath("\\jrxml")+"\\demoreport.jasper";

   String pdfFileName = getServletContext().getRealPath("\\jrxml")+"\\demoreport.pdf";

    JasperCompileManager.compileReportToFile(jrxmlFileName,jasperFileName);
    hm = new HashMap();
   hm.put("ID", "123");
   hm.put("DATENAME", "April 2006");
   
    JasperPrint jasperPrint = (JasperPrint) JasperFillManager.fillReport(jasperFileName,hm, new JREmptyDataSource());
    JasperExportManager.exportReportToPdfFile(jasperPrint, pdfFileName);
   
    System.out.println("report generated...");

------------------------------------------------------------------------------------------------------------

The Above code generates required PDF report from jasper report into a folder where jasper report files are kept...




Hide Query By Example of PanelCollection on page load

Hi All, If there is a table with filterable is true. If you want to display QueryByExample then surround this table with panelCollection....