【问题标题】:NULL values when generating a report (with Jasper Report)生成报告时的 NULL 值(使用 Jasper 报告)
【发布时间】:2014-03-20 18:06:21
【问题描述】:

Jasper 报告和 XML 数据源有一个奇怪的问题。我有两个在 iReport 中运行良好的报告(预览显示所有正确的数据),但是当我使用 JasperRunManager.runReportToPdfFile 运行报告时,值显示为空。有趣的是,两个报告中的一个有子报告,并且在子报告中,一切都正确显示!

我正在使用 XPath 进行这样的查询:

<queryString language="xPath">
    <![CDATA[/rosterArray/list/studentRoster]]>
</queryString>

而我只有一个字段:

<field name="studentName" class="java.lang.String">
    <fieldDescription><![CDATA[studentName]]></fieldDescription>
</field>

并显示它:

<detail>
    <band height="30" splitType="Stretch">
        <textField>
            <reportElement x="10" y="6" width="188" height="20"/>
            <textElement/>
            <textFieldExpression class="java.lang.String"><![CDATA[$F{studentName}]]></textFieldExpression>
        </textField>
    </band>
</detail>

XML 看起来像这样:

  <rosterArray>
   <list>
      <studentRoster>
         <studentName>Robert, Pascal</studentName>
      </studentRoster>
    </list>
  </rosterArray>

以及创建生成报告的代码:

File xmlFileName = new File(xmlDSFileName());
JRXmlDataSource xmlDS = new JRXmlDataSource(xmlFileName);
xmlDS.setDatePattern("yyyy-mm-dd HH:mm:ss.S z");

File destFile = File.createTempFile(compiledReportName, ".pdf");  
String inputFileName = PathUtilities.pathToReport(compiledReportName);

JasperRunManager.runReportToPdfFile(inputFileName, destFile.getPath(), parameters, dataSource);

【问题讨论】:

    标签: jasper-reports


    【解决方案1】:

    当您创建 JRXmlDataSource 对象时,您必须添加在 querystring 标签中定义的 xpath 选择表达式。在你的情况下,它应该是:

    JRXmlDataSource xmlDS = new JRXmlDataSource(xmlFileName, "/rosterArray/list/studentRoster");
    

    问候。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多