Compiler & Remplir Jasper Report - source de données XML

Je suis en espérant que quelqu'un peut me dire pourquoi le code ci-dessous est la création d'un vide de fichier pdf à chaque fois?

Je suis en train de compiler, de remplir et exécuter le xmldatasource exemple de projet qui est livré avec JasperReports 4.0.2. Même si je suis tenter de le faire par programmation que je veux utiliser un analogue (non ant) et de la méthode de compilation dans mon propre logiciel. Le même projet qui vient avec Jasper utilise des scripts ant pour créer le rapport et il fonctionne. Donc, je sais il n'y a aucun problème avec le JRXML fichiers. Cependant, je n'arrive pas à remplir le rapport avec les données correctement.

Quand j'ai débogué le Jaspe moteur source pour voir si mon document source XML est chargé correctement, je vois que la PARAMETER_XML_DOCUMENT avait la valeur

[document#: null]

Pensez-vous que cela signifie que le fichier source XML n'est pas lu correctement?

Le code compile et s'exécute sans erreur et tous les fichiers appropriés sont générés.jasper, .jrprint et .pdf), mais pour une raison quelconque, le rendu PDF document semble avoir seulement une page blanche à chaque fois.

Toute aide est grandement appréciée...

public static void main(String[] args) {
        Map map = new RenderReportBean().execute("northwind", "OrdersReport");

    }

    @SuppressWarnings({ "rawtypes", "unchecked" })
    public Map execute(String sourceFileId, String templateId, Integer[] formats) {
        Map params = new HashMap();
        Document document;
        Map<Integer, Boolean> renderedSuccessList = new HashMap<Integer, Boolean>();
        try {

            document = JRXmlUtils.parse(JRLoader.getLocationInputStream(sourceFileId + ".xml"));

            params.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT, document);
            params.put(JRXPathQueryExecuterFactory.XML_DATE_PATTERN, "yyyy-MM-dd");
            params.put(JRXPathQueryExecuterFactory.XML_NUMBER_PATTERN, "#,##0.##");
            params.put(JRXPathQueryExecuterFactory.XML_LOCALE, Locale.ENGLISH);
            params.put(JRParameter.REPORT_LOCALE, Locale.US);

            JasperCompileManager.compileReportToFile(templateId + ".jrxml", templateId + ".jasper");

            JasperFillManager.fillReportToFile(templateId + ".jasper", params);

            JasperExportManager.exportReportToPdfFile(templateId + ".jrprint", sourceFileId + ".pdf");


        } catch (Exception e) {
            e.printStackTrace();
            return renderedSuccessList;
        }
        return renderedSuccessList;
    }

OrdersReport.jrxml

<?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="OrdersReport" pageWidth="500" pageHeight="842" columnWidth="500" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">
<style name="Sans_Normal" isDefault="true" fontName="DejaVu Sans" fontSize="8" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false"/>
<style name="Sans_Bold" isDefault="false" fontName="DejaVu Sans" fontSize="8" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false"/>
<style name="Sans_Italic" isDefault="false" fontName="DejaVu Sans" fontSize="8" isBold="false" isItalic="true" isUnderline="false" isStrikeThrough="false"/>
<parameter name="CustomerID" class="java.lang.String"/>
<queryString language="xPath"><![CDATA[/Northwind/Orders[CustomerID='$P{CustomerID}']]]></queryString>
<field name="Id" class="java.lang.String">
<fieldDescription><![CDATA[OrderID]]></fieldDescription>
</field>
<field name="OrderDate" class="java.util.Date">
<fieldDescription><![CDATA[OrderDate]]></fieldDescription>
</field>
<field name="ShipCity" class="java.lang.String">
<fieldDescription><![CDATA[ShipCity]]></fieldDescription>
</field>
<field name="Freight" class="java.lang.Float">
<fieldDescription><![CDATA[Freight]]></fieldDescription>
</field>
<variable name="TotalFreight" class="java.lang.Float" calculation="Sum">
<variableExpression><![CDATA[$F{Freight}]]></variableExpression>
</variable>
<pageHeader>
<band height="14">
<frame>
<reportElement x="0" y="2" width="356" height="10" forecolor="#ccffff" backcolor="#ccffff" mode="Opaque"/>
<staticText>
<reportElement mode="Opaque" x="0" y="0" width="48" height="10" backcolor="#ccffff" style="Sans_Bold"/>
<textElement textAlignment="Right"/>
<text><![CDATA[ID]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="54" y="0" width="87" height="10" backcolor="#ccffff" style="Sans_Bold"/>
<textElement textAlignment="Center"/>
<text><![CDATA[Order Date]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="146" y="0" width="108" height="10" backcolor="#ccffff" style="Sans_Bold"/>
<text><![CDATA[Ship City]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="259" y="0" width="92" height="10" backcolor="#ccffff" style="Sans_Bold"/>
<textElement textAlignment="Right"/>
<text><![CDATA[Freight]]></text>
</staticText>
</frame>
</band>
</pageHeader>
<detail>
<band height="14">
<textField>
<reportElement x="0" y="2" width="51" height="10"/>
<textElement textAlignment="Right"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{Id}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" pattern="yyyy, MMM dd">
<reportElement positionType="Float" x="54" y="2" width="87" height="10"/>
<textElement textAlignment="Center"/>
<textFieldExpression class="java.util.Date"><![CDATA[$F{OrderDate}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement positionType="Float" x="146" y="2" width="108" height="10"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{ShipCity}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" pattern="¤ #,##0.00">
<reportElement positionType="Float" x="259" y="2" width="92" height="10"/>
<textElement textAlignment="Right"/>
<textFieldExpression class="java.lang.Float"><![CDATA[$F{Freight}]]></textFieldExpression>
</textField>
</band>
</detail>
<summary>
<band height="14">
<frame>
<reportElement x="0" y="2" width="356" height="10" forecolor="#33cccc" backcolor="#33cccc" mode="Opaque"/>
<staticText>
<reportElement mode="Opaque" x="160" y="0" width="67" height="10" backcolor="#33cccc" style="Sans_Bold"/>
<textElement textAlignment="Right"/>
<text><![CDATA[Total :]]></text>
</staticText>
<textField>
<reportElement mode="Opaque" x="259" y="0" width="92" height="10" backcolor="#33cccc" style="Sans_Bold"/>
<textElement textAlignment="Right"/>
<textFieldExpression class="java.lang.Float"><![CDATA[$V{TotalFreight}]]></textFieldExpression>
</textField>
<textField>
<reportElement mode="Opaque" x="227" y="0" width="27" height="10" backcolor="#33cccc" style="Sans_Bold"/>
<textElement textAlignment="Right"/>
<textFieldExpression class="java.lang.Integer"><![CDATA[$V{REPORT_COUNT}]]></textFieldExpression>
</textField>
</frame>
</band>
</summary>
</jasperReport>

CustomersReport.jrxml

<?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="CustomersReport" pageWidth="595" pageHeight="842" columnWidth="515" leftMargin="40" rightMargin="40" topMargin="50" bottomMargin="50">
<style name="Sans_Normal" isDefault="true" fontName="DejaVu Sans" fontSize="12" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false"/>
<style name="Sans_Bold" isDefault="false" fontName="DejaVu Sans" fontSize="12" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false"/>
<style name="Sans_Italic" isDefault="false" fontName="DejaVu Sans" fontSize="12" isBold="false" isItalic="true" isUnderline="false" isStrikeThrough="false"/>
<queryString language="xPath"><![CDATA[/Northwind/Customers]]></queryString>
<field name="CustomerID" class="java.lang.String">
<fieldDescription><![CDATA[CustomerID]]></fieldDescription>
</field>
<field name="CompanyName" class="java.lang.String">
<fieldDescription><![CDATA[CompanyName]]></fieldDescription>
</field>
<title>
<band height="50">
<line>
<reportElement x="0" y="0" width="515" height="1"/>
<graphicElement/>
</line>
<staticText>
<reportElement x="0" y="10" width="515" height="30" style="Sans_Normal"/>
<textElement textAlignment="Center">
<font size="22"/>
</textElement>
<text><![CDATA[Customer Orders Report]]></text>
</staticText>
</band>
</title>
<pageHeader>
<band height="21">
<staticText>
<reportElement mode="Opaque" x="0" y="5" width="515" height="15" forecolor="#ffffff" backcolor="#333333" style="Sans_Bold"/>
<text><![CDATA[Customer Order List]]></text>
</staticText>
</band>
</pageHeader>
<detail>
<band height="50">
<textField>
<reportElement x="5" y="5" width="100" height="15" isPrintWhenDetailOverflows="true" style="Sans_Bold"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{CustomerID}]]></textFieldExpression>
</textField>
<staticText>
<reportElement isPrintRepeatedValues="false" x="404" y="5" width="100" height="15" isPrintWhenDetailOverflows="true" style="Sans_Bold"/>
<text><![CDATA[(continued)]]></text>
</staticText>
<line>
<reportElement x="0" y="20" width="515" height="1" isPrintWhenDetailOverflows="true"/>
<graphicElement/>
</line>
<subreport>
<reportElement isPrintRepeatedValues="false" x="5" y="25" width="507" height="20" isRemoveLineWhenBlank="true" backcolor="#ffcc99"/>
<subreportParameter name="XML_DATA_DOCUMENT">
<subreportParameterExpression>$P{XML_DATA_DOCUMENT}</subreportParameterExpression>
</subreportParameter>
<subreportParameter name="XML_DATE_PATTERN">
<subreportParameterExpression>$P{XML_DATE_PATTERN}</subreportParameterExpression>
</subreportParameter>
<subreportParameter name="XML_NUMBER_PATTERN">
<subreportParameterExpression>$P{XML_NUMBER_PATTERN}</subreportParameterExpression>
</subreportParameter>
<subreportParameter name="XML_LOCALE">
<subreportParameterExpression>$P{XML_LOCALE}</subreportParameterExpression>
</subreportParameter>
<subreportParameter name="XML_TIME_ZONE">
<subreportParameterExpression>$P{XML_TIME_ZONE}</subreportParameterExpression>
</subreportParameter>
<subreportParameter name="CustomerID">
<subreportParameterExpression>$F{CustomerID}</subreportParameterExpression>
</subreportParameter>
<subreportExpression class="java.lang.String"><![CDATA["OrdersReport.jasper"]]></subreportExpression>
</subreport>
<textField>
<reportElement x="109" y="5" width="291" height="15" isPrintWhenDetailOverflows="true" style="Sans_Bold"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{CompanyName}]]></textFieldExpression>
</textField>
</band>
</detail>
<pageFooter>
<band height="40">
<line>
<reportElement x="0" y="10" width="515" height="1"/>
<graphicElement/>
</line>
<textField>
<reportElement x="200" y="20" width="80" height="15"/>
<textElement textAlignment="Right"/>
<textFieldExpression class="java.lang.String"><![CDATA["Page " + String.valueOf($V{PAGE_NUMBER}) + " of"]]></textFieldExpression>
</textField>
<textField evaluationTime="Report">
<reportElement x="280" y="20" width="75" height="15"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[" " + String.valueOf($V{PAGE_NUMBER})]]></textFieldExpression>
</textField>
</band>
</pageFooter>
</jasperReport>
Imprimer les chemins d'accès complets aux fichiers. Assurez-vous que les fichiers peuvent être lus par le programme. Aussi, vous devez compiler le rapport à chaque fois? Avez-vous un exemple très simple qui illustre le problème? (Quelque chose, par exemple, que d'autres ne pourrait reproduire sans trop d'effort?)

OriginalL'auteur travega | 2011-06-15