开发者

Jasper report always showing no content, why?

开发者 https://www.devze.com 2022-12-28 03:57 出处:网络
I have the following code: InputStream reportFile = MyPage.this.getClass().getResourceAsStream(\"test.jrxml\");

I have the following code:

InputStream reportFile = MyPage.this.getClass().getResourceAsStream("test.jrxml");


HashMap<String, String> parameters = new HashMap<String, String>();
parameters.put("StringParameterName", "show me");
try {
   JasperReport report = JasperCompileManager.compileReport(reportFile);
   JasperPrint print = JasperFillManager.fillReport(report, parameters);
   return JasperExportManager.exportReportToPdf(print);
} catch (JRException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    return null;
}

And the test.jrxml looks like this (I generated part of it with the iReport, the only thing I did was to remove the language="groovy" attribute):

<?xml ve开发者_开发知识库rsion="1.0" encoding="UTF-8"?>
<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="test" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <parameter name="StringParameterName" isForPrompting="false" class="java.lang.String"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="20">
          <staticText>
            <reportElement x="180" y="0" width="200" height="20"/>
            <text><![CDATA[Hello World!]]></text>
          </staticText>
        </band>
    </title>
    <pageHeader>
        <band height="35" splitType="Stretch"/>
    </pageHeader>
    <columnHeader>
        <band height="61" splitType="Stretch"/>
    </columnHeader>
    <detail>
        <band height="125" splitType="Stretch">
            <textField>
                <reportElement x="243" y="77" width="100" height="20"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[$P{StringParameterName}]]></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>

As a result I always get a blank pdf file. What could be the reason?


Instead of

JasperPrint print = JasperFillManager.fillReport(report, parameters);

I used

JasperPrint print = JasperFillManager.fillReport(report, parameters, new JREmptyDataSource());

and it worked.

Thanks!

0

精彩评论

暂无评论...
验证码 换一张
取 消