2015-12-29 50 views
1

我創建了一個Jasper報告,並且正在嘗試將報告集成到主報告中。我能夠按原樣在子報表中填充數據,但如果將其集成到主報表中,則無法呈現我在子報表中呈現的數據。事實上,我已經在我已經整合了子報表的地方把它留空了。在主報告中沒有呈現的子報表

我也給了REPORT_CONNECTION的連接表達式,並給子報表Expression提供了位於同一個項目和相同CLASSPATH中的jasper文件的位置(由「Table1Jasper.jasper」這個名字我的子報道賈斯珀)。我無法找到問題,我錯了。 以下是我正在使用的報告的代碼段。

這是我的報表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,我在哪裏我的集成報表。

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

請幫我找到我的問題,請給我一個解決方案。

回答

2

您可以使用相對路徑你的子報告,您需要使用絕對路徑

這通常通過使用參數(使用默認表達式)來實現。

<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中評估您的應用程序和相對路徑將它作爲參數圖中報告的絕對路徑傳遞。

java中的示例(參數映射中的設置參數)。

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

和......還記得當你改變你的報表,你總是需要重新編譯爲.jasper

相關問題