0

I want to save my Jaspersoft report in pdf. I have a master report with a parameter called 'REG_ID', which contains a subreport with a single parameter 'CLIENT_ID'. My main report is ready to go, when I click on the preview on Eclipse bottom tab is runs perfectly. I just wonder how can I correctly run it with a java application.

What I have tried so far (I know it doesn't work, it based on my current research):

        JasperReport jasperMasterReport = JasperCompileManager.compileReport(masterPath);
    JasperReport jasperSubReport = JasperCompileManager.compileReport(subPath);

    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("REG_ID", 56);
    parameters.put("CLIENT_ID", jasperSubReport); // I need to pass an integer to this parameter, like 1

    JasperPrint jasperPrint = JasperFillManager.fillReport(jasperSubReport, parameters, conn);

    JasperExportManager.exportReportToPdfStream(jasperPrint, new FileOutputStream(new File("C:\\Users\\<username>\\OneDrive\\Documents\\JasperReports\\reporttest1.pdf")));

Separately both of the report run, just not together.

In master report:

        <subreport>
            <reportElement x="280" y="90" width="275" height="189" uuid="fadd7392-c1a8-4fa9-9728-f70ca780d105"/>
            <subreportParameter name="CLIENT_ID">
                <subreportParameterExpression><![CDATA[$P{CLIENT_ID}]]></subreportParameterExpression>
            </subreportParameter>
            <subreportParameter name="REG_ID">
                <subreportParameterExpression><![CDATA[$P{REG_ID}]]></subreportParameterExpression>
            </subreportParameter>
            <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
            <subreportExpression><![CDATA["ClientInfo.jasper"]]></subreportExpression>
        </subreport>
Alex Denor
  • 137
  • 3
  • 16
  • I have included the master report's subreport implementation source. – Alex Denor Apr 09 '20 at 19:33
  • What is a reason to pass object of a *JasperReport* type via parameter (*CLIENT_ID*) to the subreport? – Alex K Apr 09 '20 at 19:34
  • I have read it in here: questions/9785451 to use it like that. – Alex Denor Apr 09 '20 at 19:38
  • At my answer at this post (questions/9785451) I used parameter with subreport obejct at subreportExpression. And you are using the hardcoded name (`<![CDATA["ClientInfo.jasper"]]>`). In this case the passed value (`parameters.put("CLIENT_ID", jasperSubReport)`) is not using – Alex K Apr 09 '20 at 19:41
  • Then what can I do now? – Alex Denor Apr 09 '20 at 19:55
  • 1
    I don't know the task you are trying to solve, but I can suppose that you have at least 2 options: 1) to pass the name of *jasper* (compiled template) via parameter and use it at *subreportExpression*; 2) to use the same trick as at referrenced post - pass the compiled subreport via parameter and use it at *subreportExpression* – Alex K Apr 09 '20 at 20:25
  • With your help I was able to do it, thank you so much. – Alex Denor Apr 09 '20 at 21:21

0 Answers0