简体   繁体   English

使用bean数据源和子报表在JasperReports中生成空白报表

[英]Getting blank report generated in JasperReports using bean datasource and subreports

I am creating a JasperReports 's report, which has only subreports in it. 我正在创建JasperReports的报告,其中仅包含子报告。

Following is the scenario that I am currently facing. 以下是我目前面临的情况。

For simplifying the question, let us consider only two jasper reports: mainReport and subReportFile1. 为了简化问题,让我们只考虑两个碧玉报告:mainReport和subReportFile1。

My Main report jasper file is as follows: 我的主要报告jasper文件如下:

 <?xml version="1.0" encoding="UTF-8"?>
 <!-- Created with Jaspersoft Studio version 5.6.1.final using  JasperReports Library version 5.6.1  -->
 <!-- 2015-01-28T14:21:34 -->
 <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="mainReport" pageWidth="555" pageHeight="802" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="84a1df53-5934-4d37-a3ae-44735dfd5dc3">
  <property name="com.jaspersoft.studio.unit." value="pixel"/>
  <property name="ireport.zoom" value="1.0"/>
  <property name="ireport.x" value="0"/>
  <property name="ireport.y" value="1936"/>
 <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
 <parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
     <defaultValueExpression><![CDATA["/my/file/path/jaspers/"]]></defaultValueExpression>
  </parameter>
  <parameter name="customObjectList" class="java.util.List"/>
  <detail>
    <band height="181" splitType="Stretch">
        <subreport>
            <reportElement x="0" y="3" width="554" height="157" uuid="782c39a9-1617-403c-b997-36f5cb9cdefd"/>
            <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{malwareList})]]></dataSourceExpression>
            <subreportExpression><![CDATA["/my/file/path/jaspers/subreport.jasper"]]></subreportExpression>
        </subreport>
        </band>
    </detail>
 </jasperReport>

The subreport has following fields for which I have created the following custom bean class, and send this as parameter to the main report file. 子报表具有以下字段,我为其创建了以下定制Bean类,并将其作为参数发送到主报表文件。 I have CustomBeanClass with the following fields: 我有带有以下字段的CustomBeanClass:

    String field1;
    String field2;
    private int field3;
    int field4;
    String field5;
    String date;

I am executing the following line in my java file and still I am getting a blank pdf report file. 我正在Java文件中执行以下行,但仍然得到空白的pdf报告文件。

  JasperRunManager.runReportToPdfFile(path, "/home/neeraj/test.pdf",
                parametersMap, new JREmptyDataSource());

Parameters map has the list which I send to the subreport. 参数映射具有我发送到子报表的列表。 And this is what I want to do. 这就是我想要做的。 Send the datasources of bean list to the other subreports that are present. 将Bean列表的数据源发送到存在的其他子报表。

Where am I going wrong? 我要去哪里错了?

The main report contains no records (JREmptyDataSource), therefore detail band is not processed. 主报告不包含任何记录(JREmptyDataSource),因此未处理明细区域。 Subreport in detail band is not executed. 未执行详细范围的子报表。

Move subreport into title band. 将子报表移到标题栏。 And set report property "When No Data Type" = "All Sections No Detail" 并设置报告属性“ When No Data Type” =“ All Sections No Detail”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM