wexwarez Posted October 25, 2006 Share Posted October 25, 2006 I have purchased the manuals and everything but there is no example of creating subreports with a java bean data source. I can't figure out how to do it. For instance if you were creating an inventory report. You might have a report of product categories with a subreport for each item. I would have a java bean Category that contains a property that is a Collection of items. The category report would loop on the category bean with a subreport for the items collection. How do you set the subreports data source from a field registered from the category java bean data source? thanks Link to comment Share on other sites More sharing options...
lucianc Posted October 25, 2006 Share Posted October 25, 2006 If you have a List getItems() method that returns item beans, all you need to do is to map a field to the items collection and use create a JRBeanCollectionDataSource when instantiating the subreport:Code:<import value="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>..<field name="items" class="java.util.List"/>..<subreport> .. <dataSourceExpression> new JRBeanCollectionDataSource($F{items}) </dataSourceExpression> ..</subreport> HTH,Lucian Link to comment Share on other sites More sharing options...
RoseRoo Posted October 25, 2006 Share Posted October 25, 2006 Example of master report bean:Code:private String name;private String ID;private JRDataSource workListDS; Example of sub report bean:Code:[code]private String ID;private String workName; STEP_1:Use an ArrayList to hold all sub report bean(s)Code:[code]arrayList.add(subBean1);arrayList.add(subBean2);... STEP_2:Put list into data source, and set on master beanCode:[code]JRDataSource jrds=new JRBeanCollectionDataSource(arrayList);masterBean.setWorkListDS(jrds); STEP_3:Use DataSource Expression for SubReport in iReportCode:[code]$F{workListDS} Hope it helps~:) --We are coming from TAIWAN ~_~ Link to comment Share on other sites More sharing options...
wexwarez Posted October 26, 2006 Author Share Posted October 26, 2006 RoseRoo,lucianc-Thanks for the replies. I got it working!!! Now I just need to figure out why the spacing is so funky. THanks. Link to comment Share on other sites More sharing options...
wexwarez Posted October 26, 2006 Author Share Posted October 26, 2006 RoseRoo,lucianc-Thanks for the replies. I got it working!!! Now I just need to figure out why the spacing is so funky. THanks. 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