Jump to content
Changes to the Jaspersoft community edition download ×

Print detail list content in a new page in Jasper Report


michael.samir.g

Recommended Posts

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)[/code]


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}[/code]

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}[/code]


Generating Report

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

 

And here's the report structure:
Main Report
sf9os7o.png.905145edea025d57943243fa9ce4a256.png

List details
lgrnwra.png.1de98a48d9226d1b3a00af4e379b1843.png

Report structure
vfuvmtr.png.fe88c4e606a06b0484415e4ce7128882.png

Thanks in advance

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

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

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...