2013-01-09 39 views
2

我遇到與連接到XML文件的子報表有關的問題。當我執行報告時,預覽不會顯示子報表數據,但是如果我單獨執行子報表,它會正確顯示數據。我究竟做錯了什麼?使用XML文件數據源的子報表不起作用

數據文件:

<REPORTDATA> 
<HEAD> 
    <NUMBER>1</NUMBER> 
    <DESC>BLA BLA</DESC> 
    <DATE>2012.01.01</DATE> 
</HEAD> 
<GRID1> 
    <line id="1"> 
     <NUMBER>11</NUMBER> 
     <DESC>g11BLA BLA</DESC> 
     <DATE>2012.01.01</DATE> 
    </line> 
    <line id="2"> 
     <NUMBER>12</NUMBER> 
     <DESC>g12BLA BLA</DESC> 
     <DATE>2012.01.01</DATE> 
    </line> 
</GRID1> 
<GRID2> 
    <line id="1"> 
     <NUMBER>21</NUMBER> 
     <DESC>g21BLA BLA</DESC> 
     <DATE>2012.01.01</DATE> 
    </line> 
    <line id="2"> 
     <NUMBER>22</NUMBER> 
     <DESC>g22BLA BLA</DESC> 
     <DATE>2012.01.01</DATE> 
    </line> 
</GRID2> 

報告:

<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="reporttest" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="6a9eed56-d1c3-46d8-9e16-4166c146b8a3"> 
<property name="ireport.zoom" value="1.0"/> 
<property name="ireport.x" value="0"/> 
<property name="ireport.y" value="0"/> 
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false"> 
    <defaultValueExpression><![CDATA["C:\\Users\\A2O\\Desktop\\"]]></defaultValueExpression> 
</parameter> 
<queryString language="xPath"> 
    <![CDATA[/REPORTDATA/HEAD]]> 
</queryString> 
<field name="NUMBER" class="java.lang.String"> 
    <fieldDescription><![CDATA[NUMBER]]></fieldDescription> 
</field> 
<field name="DESC" class="java.lang.String"> 
    <fieldDescription><![CDATA[DESC]]></fieldDescription> 
</field> 
<field name="DATE" class="java.lang.String"> 
    <fieldDescription><![CDATA[DATE]]></fieldDescription> 
</field> 
<background> 
    <band splitType="Stretch"/> 
</background> 
<title> 
    <band height="79" splitType="Stretch"> 
     <textField> 
      <reportElement uuid="bd7929b3-092d-44b9-b488-c0418fb57749" x="4" y="6" width="100" height="20"/> 
      <textElement/> 
      <textFieldExpression><![CDATA[$F{NUMBER}]]></textFieldExpression> 
     </textField> 
     <textField> 
      <reportElement uuid="de902808-67e8-4b08-bd0b-c1d735409843" x="6" y="32" width="100" height="20"/> 
      <textElement/> 
      <textFieldExpression><![CDATA[$F{DESC}]]></textFieldExpression> 
     </textField> 
     <textField> 
      <reportElement uuid="86d57bd0-01d3-4b1f-b9bb-0eb7cf2c19fc" x="5" y="56" width="100" height="20"/> 
      <textElement/> 
      <textFieldExpression><![CDATA[$F{DATE}]]></textFieldExpression> 
     </textField> 
    </band> 
</title> 
<pageHeader> 
    <band height="13" splitType="Stretch"/> 
</pageHeader> 
<columnHeader> 
    <band height="12" splitType="Stretch"/> 
</columnHeader> 
<detail> 
    <band height="26" splitType="Stretch"> 
     <staticText> 
      <reportElement uuid="819f4027-8ad0-46b4-b07c-c80234fe8411" x="12" y="0" width="100" height="20"/> 
      <textElement/> 
      <text><![CDATA[Static text]]></text> 
     </staticText> 
    </band> 
</detail> 
<columnFooter> 
    <band height="11" splitType="Stretch"/> 
</columnFooter> 
<pageFooter> 
    <band height="9" splitType="Stretch"/> 
</pageFooter> 
<summary> 
    <band height="42" splitType="Stretch"> 
     <subreport> 
      <reportElement uuid="4ab29d23-9ead-491e-8ca3-8f9790280026" x="0" y="0" width="555" height="42"/> 
      <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression> 
      <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "reporttest_subreport1.jasper"]]></subreportExpression> 
     </subreport> 
    </band> 
</summary> 

子報表:

<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="reporttest_subreport1" language="groovy" pageWidth="555" pageHeight="802" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="ca109af7-4e08-405d-b43f-4062115c500e"> 
<property name="ireport.zoom" value="1.0"/> 
<property name="ireport.x" value="0"/> 
<property name="ireport.y" value="0"/> 
<queryString language="xPath"> 
    <![CDATA[/REPORTDATA/GRID1/line]]> 
</queryString> 
<field name="NUMBER" class="java.lang.String"> 
    <fieldDescription><![CDATA[NUMBER]]></fieldDescription> 
</field> 
<field name="DESC" class="java.lang.String"> 
    <fieldDescription><![CDATA[DESC]]></fieldDescription> 
</field> 
<field name="DATE" class="java.lang.String"> 
    <fieldDescription><![CDATA[DATE]]></fieldDescription> 
</field> 
<background> 
    <band splitType="Stretch"/> 
</background> 
<title> 
    <band splitType="Stretch"/> 
</title> 
<pageHeader> 
    <band height="36" splitType="Stretch"/> 
</pageHeader> 
<columnHeader> 
    <band height="69" splitType="Stretch"> 
     <staticText> 
      <reportElement uuid="867a24dd-6172-40ef-be33-f8e51fa21207" x="0" y="0" width="100" height="20"/> 
      <textElement/> 
      <text><![CDATA[Grid1 data:]]></text> 
     </staticText> 
     <staticText> 
      <reportElement uuid="0885dada-a149-4cb7-b82c-fdfa9847061d" x="32" y="49" width="100" height="20"/> 
      <textElement/> 
      <text><![CDATA[NUMBER]]></text> 
     </staticText> 
     <staticText> 
      <reportElement uuid="7261c001-6771-47dc-9749-5e6f64fb86df" x="159" y="49" width="100" height="20"/> 
      <textElement/> 
      <text><![CDATA[DESC]]></text> 
     </staticText> 
     <staticText> 
      <reportElement uuid="2b95c6fc-3fd9-4df1-89c6-5249173db3e1" x="287" y="49" width="100" height="20"/> 
      <textElement/> 
      <text><![CDATA[DATE]]></text> 
     </staticText> 
    </band> 
</columnHeader> 
<detail> 
    <band height="23" splitType="Stretch"> 
     <textField> 
      <reportElement uuid="becea2ba-40fd-4208-8191-c7475293ed5b" x="32" y="1" width="100" height="20"/> 
      <textElement/> 
      <textFieldExpression><![CDATA[$F{NUMBER}]]></textFieldExpression> 
     </textField> 
     <textField> 
      <reportElement uuid="182efb3b-6a66-4634-be35-fe03e8a0cd45" x="159" y="0" width="100" height="20"/> 
      <textElement/> 
      <textFieldExpression><![CDATA[$F{DESC}]]></textFieldExpression> 
     </textField> 
     <textField> 
      <reportElement uuid="bdb70a35-b4e6-4857-96c5-f607ee59bc07" x="287" y="0" width="100" height="20"/> 
      <textElement/> 
      <textFieldExpression><![CDATA[$F{DATE}]]></textFieldExpression> 
     </textField> 
    </band> 
</detail> 
<columnFooter> 
    <band height="15" splitType="Stretch"/> 
</columnFooter> 
<pageFooter> 
    <band height="6" splitType="Stretch"/> 
</pageFooter> 
<summary> 
    <band height="7" splitType="Stretch"/> 
</summary> 

回答

2

對於使用xml文件作爲數據源的子報告,您需要指定子報告的數據源。你需要 屬性來看看是

  1. 連接類型:使用DataSource表達
  2. 連接/數據源表達:

((net.sf.jasperreports.engine.data .JRXmlDataSource)$ P {} REPORT_DATA_SOURCE)。subDataSource( 「// YOUR_SUBREPORT_ENTITY」)。

您將需要類似於此

<dataSourceExpression><![CDATA[ 

((net.sf.jasperreports.engine.data.JRXmlDataSource) 
$P{REPORT_DATA_SOURCE}).subDataSource("//YOUR_SUBREPORT_ENTITY") ]]> 
</dataSourceExpression> 
+0

感謝了很多東西。這工作。 – NeoRamza

+0

iam也有同樣的問題,但我做了你沒有得到子報告後,你有任何其他的解決方案嗎? –

+0

'「// YOUR_SUBREPORT_ENTITY」'的值是多少? @NeoRamza可以請你提供更新後的工作jrxml片段? – Manu

相關問題