0

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

1
Contributor
1
Reply
2
Views
5 Years
Discussion Span
Last Post by Kunal Lakhani
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.