views:

248

answers:

1

Hi,

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 version="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?

+1  A: 

Instead of

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

I used

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

and it worked.

Thanks!

spderosso
You can choose your answer as best :)
medopal