使用JRBeanCollectionDataSource时无法在子报表中看到表格元素数据

时间:2019-02-12 14:10:42

标签: jasper-reports

我的要求是在子报表中动态生成表格形式的数据(基于结果api),我正尝试使用参数将数据源从主报表传递到子报表中。但我看不到子报表中的表格。数据源似乎存在一些问题,当我使用JREmptyDataSource时,我可以看到表,但数据为空。请帮我解决

请在下面找到代码段和JRXml文件

**

final InputStream jasperInput =
            this.getClass().getResourceAsStream("/jasper/WorkflowSubReport.jrxml");
        final InputStream jasperSubReportInput =
                this.getClass().getResourceAsStream("/jasper/WorkflowSubReport1.jrxml");
        JasperReport jasperReport = JasperCompileManager.compileReport(jasperInput);
        JasperReport jasperSubReport = JasperCompileManager.compileReport(jasperSubReportInput);
        logger.info("Jasper Report compiled");
        Collection<WorkflowResultsDTO> data = getRunDataForDevice();

        Locale locale = new Locale("en", "US");
        ResourceBundle resourceBundle = ResourceBundle.getBundle("workflow", locale);
        HashMap<String, Object> parameters = new HashMap<>();
        parameters.put("REPORT_LOCALE", locale);
        parameters.put("REPORT_RESOURCE_BUNDLE", resourceBundle);

        String texturl = null;
        String titleImageURL = null;
        String rocheImageURL = null;
        try {
            texturl = RestClientUtil.getUrlString("pas.address_text_url", "", "", "", null);
            titleImageURL = RestClientUtil.getUrlString("pas.title_image_url", "", "", "", null);
            rocheImageURL = RestClientUtil.getUrlString("pas.roche_image_url", "","", "", null);

            URL url1 = new URL(texturl);
            InputStream in1 = new BufferedInputStream(url1.openStream());
            String text = IOUtils.toString(in1);
            in1.close();

            parameters.put("rocheLogo", rocheImageURL);
            parameters.put("headerImage", titleImageURL);
            parameters.put("textDescription", text);


        logger.info("Start of filling the report data with API response");

            JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(data);
            parameters.put("dataSource1",dataSource);
            jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, dataSource);

**

JRXml

<datasetRun subDataset="Dataset1" uuid="9cc6c316-d238-4af8-9ad7-2bae60e421d3">
                        <dataSourceExpression><![CDATA[$P{dataSource1}]]></dataSourceExpression>
                    </datasetRun>

0 个答案:

没有答案