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>();  
l.add(dse);  
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  
            e1.printStackTrace();  
    }  

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  
e/commons/beanutils/PropertyUtils  
        at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProp  
erty(JRAbstractBeanDataSource.java:115)  
        at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getFieldVal  
ue(JRAbstractBeanDataSource.java:100)  
        at net.sf.jasperreports.engine.data.JRBeanCollectionDataSource.getFieldV  
alue(JRBeanCollectionDataSource.java:104)  
        at net.sf.jasperreports.engine.fill.JRFillDataset.setOldValues(JRFillDat  
aset.java:822)  
        at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.jav  
...................  
....................  

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.