子报表未在主报表中呈现 [英] Subreport not rendering in main report

查看:137
本文介绍了子报表未在主报表中呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个Jasper报告,我正在尝试将报告整合到主报告中。我可以按原样填充子报表中的数据,但是如果我将它集成到主报表中,我将无法呈现我在子报表中呈现的数据。事实上,我在集成子报表的地方将它变为空白。

I have create a Jasper report and I am trying to integrate the report to the main report. I am able to populate the data in the subreport as-is, but if I integrate it to the main report I am not able render the data which I am rendering in the subreport. In fact I am getting it blank in the place where I have integrated the subreport.

我还给了REPORT_CONNECTION的连接表达式并给出了子报表Expression与jasper文件的位置在同一项目和相同的CLASSPATH(由Table1Jasper.jasper,这是我的子报告Jasper的名称)。我无法找到问题,我出错了。
下面是我正在处理的报告的代码片段。

I have also given the connection expression to the REPORT_CONNECTION and have give the sub-report Expression with the location of the jasper file which is in the same project and the same CLASSPATH (by "Table1Jasper.jasper" which is the name of my subreport Jasper). I am not able to find problem, where I am going wrong. Below is the code snippet of the report that I am working with.


这是我的子报告JRXML:

This is my subreport JRXML:



<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0  -->
<!-- 2015-12-29T14:51:49 -->
<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="Table1Jasper" pageWidth="250" pageHeight="842" columnWidth="250" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="168d5180-08f7-4e70-a176-9757e902e707">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="TableOneTestFactory"/>
    <property name="com.jaspersoft.studio.unit." value="pixel"/>
    <property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="a" class="java.lang.String"/>
    <field name="b" class="java.lang.Integer"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="31" splitType="Stretch">
            <staticText>
                <reportElement mode="Opaque" x="10" y="0" width="230" height="30" forecolor="#6E4A85" backcolor="#E9E1ED" uuid="c96bbba0-dd6f-4572-92ea-19b5a6165ce4"/>
                <box>
                    <topPen lineWidth="1.0" lineStyle="Double"/>
                    <leftPen lineWidth="1.0" lineStyle="Double"/>
                    <bottomPen lineWidth="1.0" lineStyle="Double"/>
                    <rightPen lineWidth="1.0" lineStyle="Double"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="14" isBold="true"/>
                </textElement>
                <text><![CDATA[TABLE ONES' FIELDS']]></text>
            </staticText>
        </band>
    </title>
    <columnHeader>
        <band height="60" splitType="Stretch">
            <staticText>
                <reportElement mode="Opaque" x="23" y="30" width="100" height="30" backcolor="#39FA50" uuid="611cad70-6062-4bc6-863c-bb4dbb4d5d55"/>
                <box>
                    <topPen lineWidth="0.5" lineStyle="Solid"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="12" isBold="true"/>
                </textElement>
                <text><![CDATA[a]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="123" y="30" width="100" height="30" backcolor="#39FA50" uuid="77893362-087e-4df0-9ca3-48acf820741f"/>
                <box>
                    <topPen lineWidth="0.5" lineStyle="Solid"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="12" isBold="true"/>
                </textElement>
                <text><![CDATA[b]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="29" splitType="Stretch">
            <textField>
                <reportElement mode="Opaque" x="23" y="-1" width="100" height="30" backcolor="#C28C8C" uuid="05928dbf-95d4-491b-9ef5-905a1fa18b2a"/>
                <box>
                    <topPen lineWidth="0.5" lineStyle="Solid"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <textFieldExpression><![CDATA[$F{a}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement mode="Opaque" x="123" y="-1" width="100" height="30" backcolor="#C28C8C" uuid="54082691-6a9e-4c28-b960-b729bdae9458"/>
                <box>
                    <topPen lineWidth="0.5" lineStyle="Solid"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <textFieldExpression><![CDATA[$F{b}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>




这是我的主报告JRXML,我正在整合我的子报告。

This is my Main report JRXML, where I am integrating my subreport.



<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0  -->
<!-- 2015-12-29T14:14:23 -->
<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="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="a0a24146-f700-4edb-8746-7825a1fa923d">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="TableOneTestFactory"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="79" splitType="Stretch">
            <staticText>
                <reportElement mode="Opaque" x="0" y="0" width="560" height="30" forecolor="#000000" backcolor="#834EED" uuid="5f92ae14-f194-4e5e-bf26-8f11a9335900"/>
                <box>
                    <topPen lineWidth="1.0" lineStyle="Double"/>
                    <leftPen lineWidth="1.0" lineStyle="Double"/>
                    <bottomPen lineWidth="1.0" lineStyle="Double"/>
                    <rightPen lineWidth="1.0" lineStyle="Double"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="20" isBold="true"/>
                </textElement>
                <text><![CDATA[Main Report]]></text>
            </staticText>
        </band>
    </title>
    <columnHeader>
        <band height="61" splitType="Stretch"/>
    </columnHeader>
    <detail>
        <band height="329" splitType="Stretch">
            <subreport>
                <reportElement x="0" y="90" width="560" height="60" uuid="021bbef9-3a86-48a1-a15f-64627101521f"/>
                <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                <subreportExpression><![CDATA["Table1Jasper.jasper"]]></subreportExpression>
            </subreport>
        </band>
    </detail>
    <columnFooter>
        <band height="45" splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band height="54" splitType="Stretch"/>
    </pageFooter>
    <summary>
        <band height="42" splitType="Stretch"/>
    </summary>
</jasperReport>

请帮我找到问题,请给我一个解决方案。

Please help me finding my problem and please give me a solution.

推荐答案

您可以使用相对路径到您的子报表,您需要使用绝对路径

You can not use relative path to your sub report, you need to use absolute path.

这通常是通过使用参数(使用默认表达式)来实现的。

This is normally achieved by using a parameter (with default expression).

示例

<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
    <defaultValueExpression><![CDATA["C:\\The\\Path\\To\\Subreport\\"]]></defaultValueExpression>
</parameter>

当致电子报告

<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "Table1Jasper.jasper"]]></subreportExpression>

使用参数可以帮助您在部署应用程序时,例如在java中评估相对路径您的应用程序并将其作为参数映射中报告的绝对路径传递。

The use of parameter helps you when deploying your application you can for example in java evaluate the relative path of your application and the pass it as absolute path to your report in the parameter map.

java中的示例(参数映射中的参数设置)。

Example in java (setting parameter in parameter map).

parameterMap.put("SUBREPORT_DIR", new File("theRelativeSubReportDir").getAbsolutePath() + File.separator);

并且......记得当您更改子报表时,您需要始终重新编译为.jasper

and... remember when you change your subreport you need always to recompile into a .jasper

这篇关于子报表未在主报表中呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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