Skip to content
Advertisement

How to compile table of contents correctly in Abstract Book using JasperReports?

I’m working on report of type Abstract Book. It includes ToC(table of contents) and subreport (JRXML):

    <group name="cover">
            <groupHeader>
                <part evaluationTime="Report" uuid="56ab525c-754f-4f48-a52c-7cc23934be3d">
                    <property name="net.sf.jasperreports.bookmarks.data.source.parameter" value="REPORT_DATA_SOURCE"/>
                    <p:subreportPart xmlns:p="http://jasperreports.sourceforge.net/jasperreports/parts"
                                     xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/parts http://jasperreports.sourceforge.net/xsd/parts.xsd">
                        <subreportParameter name="REPORT_DATA_SOURCE">
                            <subreportParameterExpression>
                                <![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("combinedReport")]]></subreportParameterExpression>
                        </subreportParameter>
                        <subreportExpression><![CDATA[$P{tocReport}]]></subreportExpression>
                    </p:subreportPart>
                </part>
            </groupHeader>
        </group>
<detail>
        <part uuid="9431bc63-c820-403c-a317-e7ffe3295dcf">
            <p:subreportPart xmlns:p="http://jasperreports.sourceforge.net/jasperreports/parts"
                             xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/parts http://jasperreports.sourceforge.net/xsd/parts.xsd">
                <subreportParameter name="REPORT_DATA_SOURCE">
                    <subreportParameterExpression>
                        <![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("combinedReport")]]></subreportParameterExpression>
                </subreportParameter>
                <subreportExpression><![CDATA[$P{subreport}]]></subreportExpression>
            </p:subreportPart>
        </part>
    </detail>

I’ve added a hyperlink to the textfield in the subreport:

<textField textAdjust="StretchHeight" hyperlinkType="LocalAnchor" bookmarkLevel="1">
                <reportElement x="0" y="0" width="280" height="30" uuid="8a8b1b38-78d3-4ab5-a728-6c0f2796371d"/>
                <textElement>
                    <font size="14" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA["Bla bla"]]></textFieldExpression>
                <anchorNameExpression><![CDATA["Bla bla"]]></anchorNameExpression>
            </textField>

However the table of contents is empty, only shows the static text “Table of contents” on the top of the page. Here is the way I compile the report (short version):

 subReport = JasperCompileManager.compileReport(jrxmlContentOutputPath);
 tocReport = JasperCompileManager.compileReport(jrxmlTocOutputPath);
InputStream templateIs = ReportPdfService.class.getClassLoader().getResourceAsStream("jasper-reports/Abstract_Book.jrxml");
Map<String, Object> parameters = new HashMap<>();
parameters.put("REPORT_DATA_SOURCE", jsonDataSource);
parameters.put("subreport", subReport);
parameters.put("tocReport", tocReport);
JasperReport report = JasperCompileManager.compileReport(templateIs);
JasperPrint jasperPrint = JasperFillManager.fillReport(report, parameters);
JasperExportManager.exportReportToPdfFile(jasperPrint, outputReportPdfPath);

I think the problem is hyperlink which is created after toc is compiled or something. But nothing works.

Advertisement

Answer

The problem was with detail band, which has parameter splitType=”Immediate”. When I removed it, ToC started working. Don’t know why it’s happening.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement