2016-01-18 230 views
0

我想用子報表創建一個簡單的賈斯珀報告,但是我不能使它工作。子報告沒有顯示

例如,我有兩個簡單的報告。

test1.jrxml
<?xml version="1.0" encoding="UTF-8"?> 
<!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0 --> 
<!-- 2016-01-18T23:29:14 --> 
<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="test1" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="553ce57f-5ea7-48e5-8eaa-dcfecf31880a"> 
    <queryString> 
     <![CDATA[select dummy from dual]]> 
    </queryString> 
    <field name="dummy" class="java.lang.String"/> 
    <background> 
     <band splitType="Stretch"/> 
    </background> 
    <title> 
     <band height="79" splitType="Stretch"/> 
    </title> 
    <pageHeader> 
     <band height="35" splitType="Stretch"/> 
    </pageHeader> 
    <columnHeader> 
     <band height="61" splitType="Stretch"> 
      <staticText> 
       <reportElement x="89" y="0" width="100" height="30" uuid="04f9b63d-265b-45f0-a249-41464df6b4c0"/> 
       <text><![CDATA[x]]></text> 
      </staticText> 
      <staticText> 
       <reportElement x="227" y="0" width="100" height="30" uuid="0c7db454-653c-4dcf-af94-a0f1c9962b91"/> 
       <text><![CDATA[x]]></text> 
      </staticText> 
      <staticText> 
       <reportElement x="352" y="0" width="100" height="30" uuid="7ad861d5-74ba-49e9-95c7-4cd01d184dbe"/> 
       <text><![CDATA[x]]></text> 
      </staticText> 
     </band> 
    </columnHeader> 
    <detail> 
     <band height="257" splitType="Stretch"> 
      <textField> 
       <reportElement x="89" y="66" width="100" height="30" uuid="4099071d-8bfc-4e61-a697-af078ccb626a"/> 
       <textFieldExpression><![CDATA[$F{dummy}]]></textFieldExpression> 
      </textField> 
      <textField> 
       <reportElement x="227" y="68" width="100" height="30" uuid="a955ca4e-aecd-48c3-8b7c-face6295b879"/> 
       <textFieldExpression><![CDATA[$F{dummy}]]></textFieldExpression> 
      </textField> 
      <textField> 
       <reportElement x="352" y="65" width="100" height="30" uuid="5a998443-ae4f-457d-a565-67b4f3405951"/> 
       <textFieldExpression><![CDATA[$F{dummy}]]></textFieldExpression> 
      </textField> 
      <subreport> 
       <reportElement x="555" y="57" width="200" height="200" uuid="d6eada20-a566-4ba5-ab51-9d6ea0b4dfd9"/> 
       <parametersMapExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}]]></parametersMapExpression> 
       <subreportParameter name="a"> 
        <subreportParameterExpression><![CDATA[12]]></subreportParameterExpression> 
       </subreportParameter> 
       <subreportExpression><![CDATA["test4.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> 

test4.jrxml
<?xml version="1.0" encoding="UTF-8"?> 
<!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0 --> 
<!-- 2016-01-18T23:27:56 --> 
<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="test4" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="c55e71d8-6eb9-4f20-9263-c50c295fa0d1"> 
    <parameter name="a" class="java.lang.String"/> 
    <queryString> 
     <![CDATA[select dummy from dual where 1=1]]> 
    </queryString> 
    <field name="dummy" class="java.lang.String"/> 
    <background> 
     <band splitType="Stretch"/> 
    </background> 
    <title> 
     <band height="79" splitType="Stretch"/> 
    </title> 
    <pageHeader> 
     <band height="35" splitType="Stretch"/> 
    </pageHeader> 
    <columnHeader> 
     <band height="61" splitType="Stretch"> 
      <staticText> 
       <reportElement x="364" y="0" width="100" height="30" uuid="1d48df0f-3f4c-489f-b479-e981b2727590"/> 
       <text><![CDATA[b]]></text> 
      </staticText> 
      <staticText> 
       <reportElement x="478" y="0" width="100" height="30" uuid="397b1c60-fe4d-4f41-a7a4-7c585a57ac15"/> 
       <text><![CDATA[a]]></text> 
      </staticText> 
     </band> 
    </columnHeader> 
    <detail> 
     <band height="125" splitType="Stretch"> 
      <staticText> 
       <reportElement x="239" y="58" width="100" height="30" uuid="5b5c86c0-1b1b-44d3-87cb-2ad2782a3408"/> 
       <text><![CDATA[test4]]></text> 
      </staticText> 
      <textField> 
       <reportElement x="364" y="66" width="100" height="30" uuid="d3217648-88a1-4d88-b2b0-7f7cc4e598c6"/> 
       <textFieldExpression><![CDATA[$F{dummy}]]></textFieldExpression> 
      </textField> 
      <textField> 
       <reportElement x="478" y="47" width="100" height="30" uuid="f2c6bfb9-ee73-4928-8ce4-0a83060d0801"/> 
       <textFieldExpression><![CDATA[$F{dummy}]]></textFieldExpression> 
      </textField> 
     </band> 
    </detail> 
    <columnFooter> 
     <band height="45" splitType="Stretch"/> 
    </columnFooter> 
    <pageFooter> 
     <band height="54" splitType="Stretch"/> 
    </pageFooter> 
    <summary> 
     <band height="42" splitType="Stretch"/> 
    </summary> 
</jasperReport> 

的選擇提供一個結果(DB是Oracle),但子報表不在從test1.jrxml所作的repport可見。但是在報告結尾處有一個全新的空白頁面。

你能告訴我這個例子有什麼問題嗎?我試了很多東西(子報表中的默認值,當沒有數據=所有部分,子報表頭中沒有詳細設置,以及很多東西,我不記得了),但沒有任何幫助。

+0

是的。我看了你的解決方案5分鐘,但我認爲,它沒有工作。 (但我不確定)我會在下週看到這個問題。 –

回答

1

在你的榜樣,我可以看到兩個問題:

  1. 你需要傳遞絕對路徑到子報表(這通常是通過參數的做法,以便它可以在運行時控制)
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false"> 
    <defaultValueExpression><![CDATA["C:\\jdd\\projects\\StackTrace\\jasper\\"]]></defaultValueExpression> 
</parameter> 

<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "test4.jasper"]]></subreportExpression> 
  • 您需要通過報告連接給子報表
  • <subreport> 
        <reportElement x="555" y="57" width="200" height="200" uuid="d6eada20-a566-4ba5-ab51-9d6ea0b4dfd9"/> 
        <parametersMapExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}]]></parametersMapExpression> 
        <subreportParameter name="a"> 
         <subreportParameterExpression><![CDATA[12]]></subreportParameterExpression> 
        </subreportParameter> 
        <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression> 
        <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "test4.jasper"]]></subreportExpression> 
    </subreport>