0 Replies Latest reply on Aug 24, 2010 7:34 AM by 807567

    Problem in passing JRBeanCollectionDataSource as parameter to jasperreport

      I had created a java class which has array list, I has passed the array list as JRBeanCollectionDataSource to jasper report as

      package cls_PrintJasper;

      import java.util.ArrayList;
      import java.util.HashMap;
      import java.util.Map;

      import net.sf.jasperreports.engine.JRException;
      import net.sf.jasperreports.engine.JRExporterParameter;
      import net.sf.jasperreports.engine.JasperFillManager;
      import net.sf.jasperreports.engine.JasperPrint;
      import net.sf.jasperreports.engine.JasperReport;
      import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
      import net.sf.jasperreports.engine.export.JRPdfExporter;
      import net.sf.jasperreports.engine.util.JRLoader;

      public class Cls_Action {

           public static void main(String ar[]) throws JRException
                try {
                     ArrayList<Cls_Bean> al=new ArrayList<Cls_Bean>();
                     Map jasperParameter = new HashMap();
                     int i;
                     //To create a Array Object//
                          Cls_Bean frm = new Cls_Bean();
                     // Path of the Jasper Report (Extension Should be ".jasper") //
                     // ".Jasper" file will be created on IReport folder (Default Location) on compilation //
                     String Context="D:/Jasper Workouts/FirstJasperReport/src/jasperDesign/Report_Main.jasper";
                     // Creating JasperReport Object //
                     JasperReport jasperReport = null;

                     // Loading the Jasper File into JasperReport Object //
                     JasperPrint jasperPrint = null;
                     // Filling the Report with Values using Parameter//
                     jasperParameter.put("sub_para", al);
                     jasperReport = (JasperReport) JRLoader.loadObject(Context);
                     jasperPrint = JasperFillManager.fillReport(jasperReport, jasperParameter,new JRBeanCollectionDataSource(al));
                     // JasperPrintManager.printReport(jasperPrint, false); //
                     // Creating JRPdfExporter object to export the report to PDF format //
                     JRPdfExporter pdfexport = new JRPdfExporter();
                     // Setting the Values as parameter //
                     pdfexport.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
                     // Setting the Destination File Name for the PDF (Extension Should be ".pdf") //
                     // Exporting the Report to PDF //
                     System.out.println("Report Generated");
                } catch (Exception e) {

      The error I am facing is

      net.sf.jasperreports.engine.JRException: Error retrieving field value from bean : new JRBeanCollectionDataSource(sub_para)

      I think the error is in jasper report, I am using ireport tool to design the reports

      My question is how to create a new parameter in the main report, and how to pass the parameter to sub report..

      PLZ help me to solve this...