在Jasper Report的新页面中打印详细信息列表内容

时间:2019-05-24 13:12:20

标签: java jasper-reports

我有一个jasper报表,它具有主报表和详细报表作为列表,数据是作为Java Bean从服务器端Java发送的,它具有一些属性,包括另一个Java Bean的列表,该列表用于填充详细信息列表,问题在于,客户需要将每个详细信息记录放在单独的页面中

我已经尝试在列表布局的末尾使用Break,但是当我尝试生成报告时,出现了错误:

Caused by: java.lang.NullPointerException
    at net.sf.jasperreports.engine.fill.JRFillBreak.prepare(JRFillBreak.java:218)
    at net.sf.jasperreports.engine.fill.JRFillElementContainer.prepareElements(JRFillElementContainer.java:537)
    at net.sf.jasperreports.components.list.FillListContents.prepare(FillListContents.java:92)
    at net.sf.jasperreports.components.list.VerticalFillList.fillContents(VerticalFillList.java:164)
    at net.sf.jasperreports.components.list.VerticalFillList.prepare(VerticalFillList.java:111)
    at net.sf.jasperreports.engine.fill.JRFillComponentElement.prepare(JRFillComponentElement.java:152)
    at net.sf.jasperreports.engine.fill.JRFillElementContainer.prepareElements(JRFillElementContainer.java:537)
    at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:411)
    at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:386)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:2024)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:748)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:255)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:115)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:582)
    at net.sf.jasperreports.engine.fill.BaseReportFiller.fill(BaseReportFiller.java:414)
    at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:121)
    at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:667)
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:983)

以下是用于生成报告的Java代码:

由于敏感的客户信息,我无法提供确切的代码,但结构相同

报告Bean:

public class ReportBean implements Serializable {

    // Main attributes used in the Main report Header and Footer
    private String attr1;
    private String attr2;
    private List<DetailBean> list;

    // setters and getters
}

Detail Bean:

public class DetailBean implements Serializable {

    // Detail attributes used in the list details to show detail records
    private String attr1;
    private String attr2;

    // setters and getters
}

正在生成报告:

// createReport() function retrieve data from data base, fill the main report information and the detail report list
ReportBean report = createReport();
String filename = "";
byte[] result = null;
try (InputStream is = new FileInputStream(filename)) {
    result = JasperReportsGenerator.createPDF(is, Collections.singletonList(report), params);
}
catch (IOException e) {}

这是报告结构:

主要报告:

Main Report

列表详细信息:

List details

报告结构:

Report structure

预先感谢

0 个答案:

没有答案