Creating a dynamic report without data source and putting data in detail band along with page footer and page header
Asked Answered
P

1

6

I am using JasperReportBuilder and exporting the report to PDF. The entire content of the report is generated by MultiPageListBuilder, HorizontalListBuilder and VerticalListBuilder and I don't want to pass the data source as data is coming from various data sources. I want to utilize page footer as well as page header for adding to static page header and footer on each page as well as page number. If I try to use addDetail(componentBuilder) method to add MultiPageListBuilder in *Detail& band (as this MultiPageListBuilder contains multiple page data), blank report generates. If I add MultiPageListBuilder in Title or Summary band, report generates perfectly but Page Header and Page Footer bands disappear.

A example code snippet is as follows

JasperReportBuilder rpt = net.sf.dynamicreports.report.builder.DynamicReports.report();
MultiPageListBuilder multiPageList = cmp.multiPageList();
HorizontalListBuilder hrbld = cmp.horizontalList();

try {    
    rpt.addTitle(cmp.text("REPORT TITLE"));
    rpt.addTitle(cmp.text("--------------"));

    rpt.addPageHeader(cmp.pageXofY());

    for (int i = 0; i < 200; i++) {
        hrbld = cmp.horizontalList();
        hrbld.add(cmp.text("ABC " + i)).newRow();
        multiPageList.add(hrbld);
    }

    rpt.addDetail(multiPageList);

    rpt.summaryOnANewPage();
    rpt.addSummary(cmp.text("REPORT SUMMARY"));

    JasperPdfExporterBuilder pdfExporter = Exporters.pdfExporter("report.pdf");
    rpt.toPdf(pdfExporter);
    File file = new File("report.pdf");

    response.setContentType("application/pdf");

    return SUCCESS;
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return ERROR;
    }

But this is not working. It generates blank report. If I use rpt.addTitle(multiPageList); instead of rpt.addDetail(multiPageList); report generates but page header doesn't appear on each page.

Please help. Thanks in advance.

Pump answered 21/5, 2013 at 12:32 Comment(0)
P
8

I found a solution that page header and page footer can be used only with the detail band. For using a detail band you need an data source attached to report. So set an empty data source to report and get the detail band where you can put data and also get use of page header and footer. A empty data source can be set as rpt.setDataSource(new JREmptyDataSource());Then report gets going with rpt.addDetail(multiPageList);. Thanks all.

Pump answered 23/5, 2013 at 11:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.