2002 JI Open Discussion Posted August 27, 2006 Share Posted August 27, 2006 By: Avinash - gavinash JRBeanCollectionDataSource in Subreports 2003-01-06 16:15 Hi, I have a bean that I will be using a datasource to fill my reports. Some properties of the bean are other beans. My report would need to populate data from both the top level (parent) as well as the children. Do I have to use subreports necessarily for the portions of the report that has the data of the child or can I do something simpler. All help is highly appreciated. Thank You Avinash By: Kjetil T. - kjetolle RE: JRBeanCollectionDataSource in Subreports 2003-10-27 23:47 Hi, I'm having the same problem. I have made two separate reports using JRBeanCollectionDataSource. One bean in report A has one or many children in report B. As standalone both reports display correctly. I then tried to merge these two reports together, making A master and B subreport. Sadly with no luck so far. I've also tried to put the report B level directly into report A by adding the children to the level A collector. This fails. Below is a skeleton of my report A. Can anyone tell me how to add the children to the parent, either by adding them to the bean collector or by using a subreport? public class AvtaleRapport { public static final String REPORT_NAME = "/resources/reports/TgAvtaleRapport.xml"; JasperReport jasperReport = null; public AvtaleRapport() { this(REPORT_NAME); } public AvtaleRapport(String reportName) { InputStream in = AvtaleRapport.class.getResourceAsStream(reportName); if (in == null) { throw new IllegalArgumentException(reportName); } try { jasperReport = JasperCompileManager.compileReport(in); } catch (JRException jre) { throw new IllegalStateException("Error while compiling report: " + jre); } } public void fillReport() throws EjbHomeFactoryException, javax.ejb.CreateException, javax.ejb.FinderException, java.rmi.RemoteException { Map parameters = new HashMap(); try { //Get the bean collection EjbHomeFactory ejbHomeFactory = EjbHomeFactory.getFactory(); AvtaleAfHome avtaleAfHome = (AvtaleAfHome) ejbHomeFactory.lookUpHome(AvtaleAfHome.class); List collector = new ArrayList(); AvtaleLevdbAltVO avtAltVO = avtaleAf.finnAvtaleLevdbAltVO(new Integer(82), new Integer(1)); collector .add(avtAltVO); } JasperPrint jasperPrint = JasperManager.fillReport(jasperReport, parameters, new JRBeanCollectionDataSource(collector)); JasperPrintManager.printReportToPdfFile(jasperPrint,PDF_FILE_NAME); JasperViewer.viewReport(jasperPrint, false); } catch (JRException jre) { throw new IllegalStateException(jre); } } Here's a skeleton of my report A By: Sumedh - stamhane RE: JRBeanCollectionDataSource in Subreports 2004-07-04 06:20 put the jar file in which the class u want to use exists into the web-inf/lib folder By: Teodor Danciu - teodord RE: JRBeanCollectionDataSource in Subreports 2003-01-07 07:08 Hi, No, you don't have to use subreports for that. All you have to know is that the JRBeanCollectionDataSource uses Java reflection based on the JavaBeans method conventions to retrieve field values. If you know that some of the parent bean "get" methods return other beans (children), then you can declare report fields of class Object and cast them to the approapriate class. This way you could call methods on them in the report expressions. Report expressions are real Java expressions, remember ? Taking this to the extreme, you could give up using any build-in data source and create you own data source which returns only one field, which is always the current parent bean. You cast it to the corresponding class and call any get method you might want on it, being able to navigate even to its child objects. I hope this makes sens and helps. Teodor By: Salman Khattak - khattaksd JRBeanCollectionDataSource Teodord / CBox 2004-06-30 20:32 I am stuck in this situtaion: To use 'casting' for fields, I believe the class should be in the classpath both at compilation and filling time. I am using Jasper in a webapp, where the classpath would not be set. Is there a way out of this rock and a hard place? By: primarykey - primarykey RE: JRBeanCollectionDataSource in Subreports 2004-07-20 00:50 I have a problem like you told and I tried to use JRBeanCollectionDataSource. My bean and child bean has been seen correctly in the report. But I couldn't understand how to show my grandchild beans in the report. Can you send a sample report and CustomDataSource implementation for this? My report style is: Parent Bean --Child Bean1 --GrandChildBean1.1 --GrandChildBean1.2 --Child Bean2 --GrandChildBean2.1 --GrandChildBean2.2 By: MLA - dozylocal RE: JRBeanCollectionDataSource in Subreports 2004-11-02 05:07 This may sound like a silly question, but how/where does one cast the fields to the correct class? In the XML? Thanks QUOTE: "If you know that some of the parent bean "get" methods return other beans (children), then you can declare report fields of class Object and cast them to the approapriate class. This way you could call methods on them in the report expressions. " 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