使用bean数据源和子报表在JasperReports中生成空白报表 [英] Getting blank report generated in JasperReports using bean datasource and subreports

查看:88
本文介绍了使用bean数据源和子报表在JasperReports中生成空白报表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个 JasperReports 的报告,该报告中只有子报告.

I am creating a JasperReports's report, which has only subreports in it.

以下是我当前面临的情况.

Following is the scenario that I am currently facing.

为简化问题,让我们仅考虑两个碧玉报告: mainReport和subReportFile1.

For simplifying the question, let us consider only two jasper reports: mainReport and subReportFile1.

我的主要报告jasper文件如下:

My Main report jasper file is as follows:

 <?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>

子报表具有以下字段,我已经为其创建以下定制Bean类,并将其作为参数发送到主报表文件. 我有具有以下字段的CustomBeanClass:

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. I have CustomBeanClass with the following fields:

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

我正在Java文件中执行以下行,但仍得到空白的pdf报告文件.

I am executing the following line in my java file and still I am getting a blank pdf report file.

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

Parameters映射具有我发送到子报表的列表.这就是我想要做的.将Bean列表的数据源发送到存在的其他子报表中.

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.

我要去哪里错了?

推荐答案

主报告不包含任何记录(JREmptyDataSource),因此未处理明细区域.未执行详细区域的子报表.

The main report contains no records (JREmptyDataSource), therefore detail band is not processed. Subreport in detail band is not executed.

将子报表移至标题栏.并设置报告属性"When No Data Type" ="All Sections No Detail"

Move subreport into title band. And set report property "When No Data Type" = "All Sections No Detail"

这篇关于使用bean数据源和子报表在JasperReports中生成空白报表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆