nedPhillips Posted December 1, 2007 Share Posted December 1, 2007 I need to create a PDF report from data stored in a HashMap. The keys are the columns, the values are the column values. Pretty straight forward. Please do not tell me to look at the Samples. The samples have been some help but not a complete solution. Do I need to use a JRDataSource? I want to compile a jasper file in iReport. How do I setup my Custom DataSource in iReport? What other JR Classes to I need to use? fillReportToFile? which signature? exportReportToPdf? Anything else? I would love to see a solid example showing how to do this with iReport and the jasperreports api. Thanksthe contents of my HashMap. Link to comment Share on other sites More sharing options...
nedPhillips Posted December 3, 2007 Author Share Posted December 3, 2007 Anyone! Link to comment Share on other sites More sharing options...
nedPhillips Posted December 4, 2007 Author Share Posted December 4, 2007 Here is some additional information. I'm using iReport and Jasperreports API both versions are 1.2.7. I think I need to create either a JRDataSource or a JRDataSourceProvider class. A Factory class with a static method (e.g. getDataSource) that takes no parameters. As I stated in my first post. I have a Hashmap class with the key values being the column (field) names for the report, and the Hashmap values contain the information for those key/column/field names. Do I need to pass the Hashmap into my JRDataSource/JRDataSourceProvider class ? How do I setup my Custom DataSource in iReport. Do I use an empty DataSource? How is that done? Note: I do not need to hit the database since I've already pulled the data into my Hashmap. This does not seem to be a difficult report to implement, however, I have not had any luck following the jasperreport samples or searching on the internet for answers. Thanks for any help provided. Link to comment Share on other sites More sharing options...
lucianc Posted December 5, 2007 Share Posted December 5, 2007 This seems to be more of an iReport related question. Have you tried posting on the iReport forum? I'm not an iReport expert, but I guess you do have to use either a Custom JRDataSource or a JRDataSourceProvider. The code would have to fetch your data HashMap and create a JR data source based on it. For instance, a Custom JRDataSource factory class would doCode:public class MyDataSourceFactory { public JRDataSource createDatasource() { HashMap data = ..fetch the data map..; return new JRMapArrayDataSource(new Map[]{data}); }} After you have the class, you'll have to create the iReport data source (via Data -> Connections/Data Sources), and use it as "active connection" when running the report. HTH,Lucian Link to comment Share on other sites More sharing options...
nedPhillips Posted December 6, 2007 Author Share Posted December 6, 2007 lucian, Thanks for your reply, however, I was able to get my report working but without using a Factory or Provider. All I used was a JRDataSource interface. I can write up some detailed documentation of how I did this after I finalize my report. Link to comment Share on other sites More sharing options...
suryakusumakar Posted December 8, 2007 Share Posted December 8, 2007 i m also facing the same problem.I m passing HashMap object to method runReportToPdfStream() that object contains number of records from database .I m using JRDatasource but i m getting blank PDF.Can anyone answer me y his is happening???:( Link to comment Share on other sites More sharing options...
teodord Posted December 14, 2007 Share Posted December 14, 2007 Hi, I suspect you passed the HaspMap containing your records in the place for the report parameters map. If so, no wonder it does not work, as the report will run without a data source and will result in an empty document.There is a separate argument in the method for passing the data source.You'll probably have to wrap the values of the map in a JRBeanCollectionDataSource instance.If you need more details about using data sources, check the /demo/samples/datasource sample provided with the project. I hope this helps.Teodor Link to comment Share on other sites More sharing options...
suryakusumakar Posted December 15, 2007 Share Posted December 15, 2007 I have tried it using CustomDataSource and Custombeanfactory snippet:long start = System.currentTimeMillis(); //Preparing parameters Map parameters = new HashMap(); parameters.put("ReportTitle", "Address Report"); parameters.put("DataFile", "ReportBeanFactory.java - Bean Collection"); JasperFillManager.fillReportToFile(fileName, parameters, new JRBeanCollectionDataSource(ReportBeanFactory.getBeanCollection())); System.err.println("Filling time : " + (System.currentTimeMillis() - start)); System.exit(0); but i m getting exception:Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/javaflow/bytecode/Continuable at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:620) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124) at java.net.URLClassLoader.defineClass(URLClassLoader.java:260) at java.net.URLClassLoader.access$100(URLClassLoader.java:56) at java.net.URLClassLoader$1.run(URLClassLoader.java:195) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268) at java.lang.ClassLoader.loadClass(ClassLoader.java:251) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319) at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:601) at net.sf.jasperreports.engine.JasperFillManager.fillReportToFile(JasperFillManager.java:492) at net.sf.jasperreports.engine.JasperFillManager.fillReportToFile(JasperFillManager.java:448) at ReportDataSourceApp.main(ReportDataSourceApp.java:40) Process completed.:(Post edited by: suryakusumakar, at: 2007/12/14 18:04 Link to comment Share on other sites More sharing options...
teodord Posted December 19, 2007 Share Posted December 19, 2007 Hi, I suspect you have the jasperreports-x.x.x-javaflow.jar in your classpath.If you do not know what it is for, then you don't need it, and should have the jasperreports-x.x.x.jar only. I hope this helps.Teodor 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