I collected the data off the form and placed it in a bean class, DataBean.

JRBeanCollectionDataSource constructor takes Collection as parameter, so i should convert the bean data into some kind of collection, like list, and then pass it into JRBeanCollectionDataSource and pass its instance to JasperManager.fillReport method.

In iReport "$F(fieldName) notation" will be $F(bean properties name)

Here is the code

List<DemandSlipEntity> l = new ArrayList<DemandSlipEntity>();  
JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(l);  
InputStream in = this.getClass().getClassLoader().getResourceAsStream("reports/Demand Slip.jasper");  
 try {  
    System.out.println("insidse try");  
    JasperPrint jpr = JasperFillManager.fillReport(in, null, ds);  
    //JasperExportManager.exportReportToPdfFile(jpr, "C:\\demand.pdf");  
        JasperViewer.viewReport(jpr, false);  

    } catch (JRException e1) {  
            // TODO Auto-generated catch block  

where dse is the instance of DemandSlipEntity class. In demand Slip.jasper i have used the properties of DemandSlipEntity, such as $F{name}, where name is a property of DemandSlipEntity.

This code gives the following exception :

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apach  
        at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProp  
        at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getFieldVal  
        at net.sf.jasperreports.engine.data.JRBeanCollectionDataSource.getFieldV  
        at net.sf.jasperreports.engine.fill.JRFillDataset.setOldValues(JRFillDat  
        at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.jav  

I have added commons-beanutils to the classpath, but still same problem

This article has been dead for over six months. Start a new discussion instead.