Print detail list content in a new page in Jasper Report

0

I have a jasper report that has main report and detail report as a list, the data is being sent from server side Java as a java bean that has some attributes including a list of another Java bean, this list is used to fill the detail list, the problem is that, the client need that each detail record should be in a separate page

I already try to use Break at end of the list layout, but when I try to generate the report I got the error:

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)


Here's the java code for generating the report:

due to sensitive client information I couldn't provide the exact code but the same structure

Report 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
}


Generating Report

// 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) {}

And here's the report structure:
Main Report

List details

Report structure

Thanks in advance

michael.samir.g's picture
Joined: May 24 2019 - 6:19am
Last seen: 1 month 4 weeks ago

1 Answer:

0

Don't use list element...my experience says, that un most cases you will come to rhe limitations of list element and you will refactor it to subreport. So just change to subreport and place the break element into the detail section of the subreport, so that each record will do an break.

You could then also use groups and also the group feature StartOnNewPage

Hth + regards

C-Box

C-Box's picture
1622
Joined: Jul 19 2006 - 5:58pm
Last seen: 4 days 21 hours ago
Feedback
randomness