2013-02-15 269 views
0

我有一个报告,显示它的项目,因为它应该。 现在我需要添加3个子报告到主要报告。在JasperReport的主报告中添加子报告

对于这个我使用iReports。

我的问题是,如何将项目列表传递给子报表? 我发现了一些教程,但在这些情况下,子报告的数据在第一个报告中。

在我的情况下,我有一个4详细带的报告,其中3与子报告。

我的代码:

JRBeanCollectionDataSource beanCollection = new JRBeanCollectionDataSource(report.getList()); 
     jasperPrint = JasperFillManager.fillReport("C:\\Users\\Desktop\\Report.jasper", new HashMap(), beanCollection) ; 
HttpServletResponse http = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse(); 
     http.addHeader("Content-disposition", "attachment; filename=report.pdf"); 
     ServletOutputStream stream = http.getOutputStream(); 
     JasperExportManager.exportReportToPdfStream(jasperPrint, stream); 

我使用JSF 2.0。

ps:我看到我可以创建4个jasperPrint,并将每个页面添加到主报告中,但是我想知道它是否可能是我寻找的。

问候。

回答

0

我终于做到了:

for(JRPrintPage p : jasperPrint1.getPages()){ 

    jasperPrint.addPage(p); 
} 

其中jasperPrint是主报告和jasperPrint1是子报表(即报告它的自我)。通过这种方式,我可以将项目列表正常传递给所有报告。

JRBeanCollectionDataSource beanCollection1 = new JRBeanCollectionDataSource(report.getSections().get(1).getRowsReports()); 
     JasperPrint jasperPrint1 = JasperFillManager.fillReport("C:\\Users\\Desktop\\Meeting.jasper", new HashMap(), beanCollection1) ; 
0

假设你的数据源的结构如下

public class MyPOJO{ 
    private List<POJOSubData1> sub1; 
    private List<POJOSubData2> sub2; 
    private List<POJOSubData3> sub3; 

    //getters & setters 
    ... 
} 

可以通过指定的理想的数据源到你的子报表以下子报表的属性

Connection type : Use a datasource expression 
Data Source Expression : $F{sub1} //or sub2 or sub3 

sub1Field ClassList

此外,您不需要将隔离1子报表放置到1个细节带,您可以将所有子报告放在一个细节带中。

0

如果您使用Ireport创建报告,然后在Ireport中打开主报告并选择子报表并转到报告的属性部分,单击“参数”属性并单击“从主复制”选项卡,从那里您可以选择你想传递给太阳报告的参数。