2005 IR Help Posted September 2, 2006 Share Posted September 2, 2006 By: Strat - larynf Accessing an array using JavaBean datasource 2005-10-17 13:50 Have these two classes and using JavaBean datasource, I need to display the contents of the details field in my report. ClassA { private ClassB[] variable1; .... } ClassB { private String details; .... public String getDetails() { return details; } public void setDetails(String str) { details = str; } } Currently subclassed a JRAbstractBeanDataSourceProvider and in the method public JRDataSource create(JasperReport report) throws JRException ( ), I return JRBeanCollectionDataSource(list) where list is an ArrayList of ClassA I created ((com.test.AgreementType[])$F{agreementType})[0].getDetails() as a variable in the report template and dropped it on my report template. It compiles but I get this exception when I run the report Compiling to file... C:deveclipseworkspacedemo2Agreement_Bean.jasper -> C:deveclipseworkspacedemo2Agreement_Bean.java it.businesslogic.ireport.ReportClassLoader@372b61 Compilation running time : 235 Filling report... Error filling print... java.lang.ClassCastException: [Lcom.test.AgreementType; at Agreement_Bean.evaluate(Agreement_Bean:154) at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:608) at net.sf.jasperreports.engine.fill.JRCalculator.calculateVariables(JRCalculator.java:145) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:576) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:226) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:129) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:953) at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:89) at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:428) at it.businesslogic.ireport.IReportCompiler.run(IReportCompiler.java:637) at java.lang.Thread.run(Unknown Source By: Strat - larynf RE: Accessing an array using JavaBean datasou 2005-10-20 12:06 So I noticed a typo in my previous email. It should read... I created ((com.test.ClassB[])$F{variable1})[0].getDetails() as a variable in the report template and dropped it on my report template. I got it to work but only after writing a test program which calls the JasperReports API directly. If I run it from within iReport, it still reports a class cast exception. But here's another question I can access the first element using the above expression. How do I get iReport to loop thru' all the instance of variable1 ( and then access getDetails() for each instance) since the above expression will only get me the first ClassB object ? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now