Java Don';t查看来自第二张JasperPrint的数据

Java Don';t查看来自第二张JasperPrint的数据,java,jasper-reports,Java,Jasper Reports,我想从许多其他JasperReport创建一个报告。但我看不到数据,这是第一张茉莉花印之后的数据。如果我将更改位置jasperPrintTracking和jasperprintdefation。您将看到我首先编写的JasperPrint的数据,但第二个JasperPrint没有任何数据。如果我先写了jasperPrintTracking,我会看到jasperPrintTracking中的数据,但是a看不到jasperPrintTracking中的数据,他们没有下载。为什么会这样 public c

我想从许多其他JasperReport创建一个报告。但我看不到数据,这是第一张茉莉花印之后的数据。如果我将更改位置
jasperPrintTracking
jasperprintdefation
。您将看到我首先编写的JasperPrint的数据,但第二个JasperPrint没有任何数据。如果我先写了
jasperPrintTracking
,我会看到
jasperPrintTracking
中的数据,但是a看不到
jasperPrintTracking
中的数据,他们没有下载。为什么会这样

public class RoadReport {
    JasperPrint jasperPrintDeparture;
    JasperPrint jasperPrintTracking;
    CardFile cardFile = new CardFile();

    public void createRoadReport (List <StatisticsOnPassengerTrainByMonth> passsenger, List<StatisticsOnCommuterTrainByMonth> commuter, List<StatisticsOnFreightTrainByMonth> freight){
        JRBeanCollectionDataSource passengerDataSource = new JRBeanCollectionDataSource(passsenger);
        JRBeanCollectionDataSource commuterDataSource = new JRBeanCollectionDataSource(commuter);
        JRBeanCollectionDataSource freightDataSource  = new JRBeanCollectionDataSource(freight);

        Map <String, Object> parametr = new HashMap<String, Object>();
        parametr.put("PassengerDataSource", passengerDataSource);
        parametr.put("CommuterDataSource", commuterDataSource);
        parametr.put("FreightDataSource", freightDataSource);

        try {
            jasperPrintDeparture = JasperFillManager.fillReport((FacesContext.getCurrentInstance().getExternalContext().getRealPath("/ReportRoadDeparture.jasper")), parametr, new JREmptyDataSource());
            jasperPrintTracking = JasperFillManager.fillReport((FacesContext.getCurrentInstance().getExternalContext().getRealPath("/ReportRoadTracking.jasper")), parametr, new JREmptyDataSource());
            multipageLinking(jasperPrintDeparture, jasperPrintTracking);
            JasperExportManager.exportReportToPdfFile(jasperPrintDeparture, FacesContext.getCurrentInstance().getExternalContext().getRealPath("/report1.pdf"));
        } catch (JRException e) {
            e.printStackTrace();
        }
    }

    @SuppressWarnings("rawtypes")
    private JasperPrint multipageLinking(JasperPrint file1, JasperPrint file2) {
        List pages = file2.getPages();
        for (int count = 0; count <
                pages.size(); count++) {
            file1.addPage((JRPrintPage) pages.get(count));
        }

        return file1;
    }
}
公共类道路报告{
茉莉花;
茉莉花;
CardFile CardFile=新的CardFile();
public void createRoadReport(列出乘客,列出通勤者,列出运费){
JRBeanCollectionDataSource passengerDataSource=新的JRBeanCollectionDataSource(passsenger);
JRBeanCollectionDataSource ConverterDataSource=新的JRBeanCollectionDataSource(通勤者);
JRBeanCollectionDataSource freightDataSource=新的JRBeanCollectionDataSource(运费);
Map parametr=newhashmap();
参数put(“PassengerDataSource”,PassengerDataSource);
参数put(“通勤数据源”,通勤数据源);
参数put(“FreightDataSource”,FreightDataSource);
试一试{
JasperPrintDeviation=JasperFillManager.fillReport((FacesContext.getCurrentInstance().getExternalContext().getRealPath(“/ReportRoadDeviation.jasper”)),Parameter,新JREmptyDataSource());
jasperPrintTracking=JasperFillManager.fillReport((FacesContext.getCurrentInstance().getExternalContext().getRealPath(“/ReportRoadTracking.jasper”)),Parameter,新JREmptyDataSource());
多标签链接(JasperPrintDeviation、jasperPrintTracking);
JasperExportManager.exportReportToPdfFile(JasperPrintExample,FacesContext.getCurrentInstance().getExternalContext().getRealPath(“/report1.pdf”);
}捕获(JRE异常){
e、 printStackTrace();
}
}
@抑制警告(“原始类型”)
私有JasperPrint多页面链接(JasperPrint文件1、JasperPrint文件2){
List pages=file2.getPages();
对于(int count=0;count<
pages.size();count++){
file1.addPage((JRPrintPage)pages.get(count));
}
返回文件1;
}
}
报告的图像如下所示


贝克扬,你的方法没用。结果是一样的。我找到了解决我问题的办法。对于每个jasperPrint变量,必须创建新的JRBeanCollectionDataSource。我的代码如下

public void createRoadReport (List <StatisticsOnPassengerTrainByMonth> passsenger, List<StatisticsOnCommuterTrainByMonth> commuter, List<StatisticsOnFreightTrainByMonth> freight, String dateReport) throws JRException{
    List<JasperPrint> jasperPrintList = new ArrayList<JasperPrint>();

    for (int i = 0; i < 3; i++) {
        JRBeanCollectionDataSource passengerDataSource = new JRBeanCollectionDataSource(passsenger);
        JRBeanCollectionDataSource commuterDataSource = new JRBeanCollectionDataSource(commuter);
        JRBeanCollectionDataSource freightDataSource  = new JRBeanCollectionDataSource(freight);

        Map <String, Object> parametr = new HashMap<String, Object>();
        parametr.put("PassengerDataSource", passengerDataSource);
        parametr.put("CommuterDataSource", commuterDataSource);
        parametr.put("FreightDataSource", freightDataSource);
        parametr.put("date", dateReport);
        switch (i) {
        case 0:
            jasperPrintDeparture = JasperFillManager.fillReport((FacesContext.getCurrentInstance().getExternalContext().getRealPath("/ReportRoadDeparture.jasper")), parametr, new JREmptyDataSource());
            jasperPrintList.add(jasperPrintDeparture);
        break;
        case 1:
            jasperPrintTracking = JasperFillManager.fillReport((FacesContext.getCurrentInstance().getExternalContext().getRealPath("/ReportRoadTracking.jasper")), parametr, new JREmptyDataSource());
            jasperPrintList.add(jasperPrintTracking);
        break;
        case 2:
            jasperPrintArrival = JasperFillManager.fillReport((FacesContext.getCurrentInstance().getExternalContext().getRealPath("/ReportRoadArrival.jasper")), parametr, new JREmptyDataSource());
            jasperPrintList.add(jasperPrintArrival);
        break;
        }
    }

        //multipageLinking(jasperPrintDeparture, jasperPrintTracking);
        //JasperExportManager.exportReportToPdfFile(jasperPrintArrival, FacesContext.getCurrentInstance().getExternalContext().getRealPath("/report.pdf"));
        JRPdfExporter exporter = new JRPdfExporter();
        exporter.setExporterInput(SimpleExporterInput.getInstance(jasperPrintList)); //Set as export input my list with JasperPrint s
        exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(FacesContext.getCurrentInstance().getExternalContext().getRealPath("/report.pdf"))); //or any other out streaam
        SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
        configuration.setCreatingBatchModeBookmarks(true); //add this so your bookmarks work, you may set other parameters
        exporter.setConfiguration(configuration);
        exporter.exportReport();

}
public void createRoadReport(列表乘客、列表通勤者、列表运费、字符串日期报告)引发异常{
List jasperPrintList=newarraylist();
对于(int i=0;i<3;i++){
JRBeanCollectionDataSource passengerDataSource=新的JRBeanCollectionDataSource(passsenger);
JRBeanCollectionDataSource ConverterDataSource=新的JRBeanCollectionDataSource(通勤者);
JRBeanCollectionDataSource freightDataSource=新的JRBeanCollectionDataSource(运费);
Map parametr=newhashmap();
参数put(“PassengerDataSource”,PassengerDataSource);
参数put(“通勤数据源”,通勤数据源);
参数put(“FreightDataSource”,FreightDataSource);
参数put(“日期”,日期报告);
开关(一){
案例0:
JasperPrintDeviation=JasperFillManager.fillReport((FacesContext.getCurrentInstance().getExternalContext().getRealPath(“/ReportRoadDeviation.jasper”)),Parameter,新JREmptyDataSource());
jasperPrintList.add(jasperPrintList);
打破
案例1:
jasperPrintTracking=JasperFillManager.fillReport((FacesContext.getCurrentInstance().getExternalContext().getRealPath(“/ReportRoadTracking.jasper”)),Parameter,新JREmptyDataSource());
jasperPrintList.add(jasperPrintTracking);
打破
案例2:
jasperPrintArrival=JasperFillManager.fillReport((FacesContext.getCurrentInstance().getExternalContext().getRealPath(“/ReportRoadArrival.jasper”)),Parameter,新JREmptyDataSource());
jasperPrintList.add(jasperPrintArrival);
打破
}
}
//多标签链接(JasperPrintDeviation、jasperPrintTracking);
//JasperExportManager.exportReportToPdfFile(jasperPrintArrival,FacesContext.getCurrentInstance().getExternalContext().getRealPath(“/report.pdf”);
JRPdfExporter exporter=新的JRPdfExporter();
exporter.setExporterInput(SimpleExporterInput.getInstance(jasperPrintList));//将带有JasperPrints的我的列表设置为导出输入
exporter.setExporterOutput(新的SimpleOutputStreamExportRoutPut(FacesContext.getCurrentInstance().getExternalContext().getRealPath(“/report.pdf”);//或任何其他输出路径
SimplePDExporterConfiguration配置=新的SimplePDExporterConfiguration();
configuration.setCreatingBatchModeBookmarks(true);//添加此选项以便书签工作,您可以设置其他参数
exporter.setConfiguration(配置);
出口商。出口报告();
}
提供了另一种合并报告的方法。也许你应该先检查一下。