4

I'm creating a Jasper Report using Dynamic Reports library. I'm trying to compile the dynamic reports, to use compiled version later. But the compiled version of my report is not reflecting the changes that are made dynamic reports

This is my code:

JasperReportBuilder report = report();
report.setTemplateDesign(new File("Template.jrxml"));
report.setParameters(parameters);

List<TextColumnBuilder> lsColumns = getDRColumnsFromRecordset(rs);
for (TextColumnBuilder tcbColumn : lsColumns) {
    report.addColumn(tcbColumn);
}
report.ignorePageWidth();
report.ignorePagination();
report.setDataSource(rs);
report.toXlsx();

//At the end, i compile the dynamic report
File compiledTemplate = new File("CompiledTemplate.jasper");
JasperCompileManager.compileReportToFile(report.toJasperDesign(), compiledTemplate.getPath());

In the above code, it generates correctly (when i run .toXlsx())

But, at another point of the application, i check if the compiled template exists. If it exists, i use the compiled template to generate the report.

However, when I try to generate template using compiled version, it returns empty.

It is generating without the record set columns - who I have added dynamically in the above code.

Updating status
31/08/2016
My situation is: I have a procedure that contain dynamic output (depending of the parameter you receive). Hence when the procedure receive @Cod = 1 argument, for example, it will have a particular SQL output. I want the first time you run the Dynamic Reports, generates the compiled report (.jasper) based on the procedure output. And in subsequent times, I can reuse the compiled report (.jasper) to generate new reports using it only.

I solved part of the problem. When it runs at second time, there was no SQL within the jrxml template. So, I inserted the following code in that template jrxml:


    <parameter name="QUERY" class="java.lang.String" isForPrompting="false"/>
    <queryString>
        <![CDATA[$P!{QUERY}]]>
    </queryString>

And i've insert the following code in my program (when using .jasper generated in DynamicReports):

JasperReport jasperReport = (JasperReport) JRLoader.loadObject(compiledTemplate);        
parameters.put("QUERY", "dbo.pr_test_procedure @Cod=" + parameters.get("COD")); 
        JasperPrint jasperPrint
                = JasperFillManager.fillReport(jasperReport,
                        parameters,
                        conn);

Now the report brings the results of the query (as featured in Dynamic Reports). Now, the problem is another: It does not display the column header. Only displays the records. When i generate by Dynamic Reports, show the both. When generates using compiled jasper, show only the records.

My results now: This is the report in Dynamic Reports (without compiling): https://s21.postimg.org/arh0w5isn/relatorio_1.jpg This is the report after being compiled, generated in Jasper https://s17.postimg.org/iozct8mwf/relatorio_2.jpg

This is the jrxml of compiled file:


<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.1.1.final using JasperReports Library version 6.1.1  -->
<!-- 2016-08-31T14:20:33 -->
<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="Template_Basico" pageWidth="1392" pageHeight="595" orientation="Landscape" whenNoDataType="AllSectionsNoDetail" columnWidth="1352" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isIgnorePagination="true" uuid="8a465670-cc4a-4270-965f-8efb86e33b71">
    <property name="template.engine" value="tabular_template"/>
    <property name="net.sf.jasperreports.export.xls.detect.cell.type" value="true"/>
    <property name="net.sf.jasperreports.export.xls.show.gridlines" value="false"/>
    <template><![CDATA[$P{PATH_PADRAODSM} + "/" + "Template_Basico.jrtx"]]></template>
    <style name="TabelaCabecalho" mode="Opaque" backcolor="#4692F0" scaleImage="FillFrame" isBlankWhenNull="true" fontName="SansSerif" fontSize="13" isBold="true">
        <pen lineStyle="Solid" lineColor="#000000"/>
        <box>
            <topPen lineWidth="1.0"/>
            <leftPen lineWidth="1.0"/>
            <bottomPen lineWidth="1.0"/>
            <rightPen lineWidth="1.0"/>
        </box>
    </style>
    <style name="style_36_" forecolor="#000000" isBlankWhenNull="true" fontName="SansSerif" fontSize="10">
        <box topPadding="2" leftPadding="2" bottomPadding="2" rightPadding="2"/>
    </style>
    <style name="Fonte" pattern="" isBlankWhenNull="true" fontName="Verdana" fontSize="11" isBold="false"/>
    <subDataset name="tableDataset" uuid="73560e0d-a48c-4cef-a6c7-dc2799080847">
        <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
        <queryString>
            <![CDATA[]]>
        </queryString>
    </subDataset>
    <scriptlet name="DYNAMICREPORTS" class="net.sf.dynamicreports.jasper.base.JasperScriptlet"/>
    <parameter name="CODPEDIDO" class="java.lang.Integer">
        <parameterDescription><![CDATA[Código do pedido do relatório]]></parameterDescription>
        <defaultValueExpression><![CDATA[90200]]></defaultValueExpression>
    </parameter>
    <parameter name="PATH" class="java.lang.String" isForPrompting="false">
        <parameterDescription><![CDATA[]]></parameterDescription>
        <defaultValueExpression><![CDATA["/home/diego.queres/Desenv/Relatórios Clientes/PadraoDSM_Templates"]]></defaultValueExpression>
    </parameter>
    <parameter name="TITULO" class="java.lang.String">
        <defaultValueExpression><![CDATA["Relatório"]]></defaultValueExpression>
    </parameter>
    <parameter name="LOGOTIPO_1" class="java.lang.String" isForPrompting="false">
        <parameterDescription><![CDATA[]]></parameterDescription>
        <defaultValueExpression><![CDATA["logo-vagas.png"]]></defaultValueExpression>
    </parameter>
    <parameter name="PATH_PADRAODSM" class="java.lang.String">
        <defaultValueExpression><![CDATA["/home/diego.queres/Desenv/Relatórios Clientes/PadraoDSM_Templates"]]></defaultValueExpression>
    </parameter>
    <parameter name="QUERY" class="java.lang.String" isForPrompting="false"/>
    <parameter name="CUSTOM_VALUES" class="net.sf.dynamicreports.jasper.base.JasperCustomValues"/>
    <queryString>
        <![CDATA[$P!{QUERY}]]>
    </queryString>
    <field name="Codigo do candidato" class="java.lang.Integer">
        <fieldDescription><![CDATA[Codigo do candidato]]></fieldDescription>
    </field>
    <field name="Nome" class="java.lang.String">
        <fieldDescription><![CDATA[Nome]]></fieldDescription>
    </field>
    <field name="E-mail" class="java.lang.String">
        <fieldDescription><![CDATA[E-mail]]></fieldDescription>
    </field>
    <field name="Idade" class="java.lang.Integer">
        <fieldDescription><![CDATA[Idade]]></fieldDescription>
    </field>
    <field name="Telefone(s) Contato" class="java.lang.String">
        <fieldDescription><![CDATA[Telefone(s) Contato]]></fieldDescription>
    </field>
    <field name="Cidade e Estado" class="java.lang.String">
        <fieldDescription><![CDATA[Cidade e Estado]]></fieldDescription>
    </field>
    <field name="Tipo de Formação 1" class="java.lang.String">
        <fieldDescription><![CDATA[Tipo de Formação 1]]></fieldDescription>
    </field>
    <field name="Formação 1" class="java.lang.String">
        <fieldDescription><![CDATA[Formação 1]]></fieldDescription>
    </field>
    <field name="Instituição 1" class="java.lang.String">
        <fieldDescription><![CDATA[Instituição 1]]></fieldDescription>
    </field>
    <field name="Tipo de Formação 2" class="java.lang.String">
        <fieldDescription><![CDATA[Tipo de Formação 2]]></fieldDescription>
    </field>
    <field name="Formação 2" class="java.lang.String">
        <fieldDescription><![CDATA[Formação 2]]></fieldDescription>
    </field>
    <field name="Instituição 2" class="java.lang.String">
        <fieldDescription><![CDATA[Instituição 2]]></fieldDescription>
    </field>
    <field name="Histórico profissional (2 últimas empresas)" class="java.lang.String">
        <fieldDescription><![CDATA[Histórico profissional (2 últimas empresas)]]></fieldDescription>
    </field>
    <title>
        <band height="76" splitType="Stretch">
            <image scaleImage="RetainShape">
                <reportElement x="22" y="32" width="100" height="40" uuid="6047dd6f-0536-4689-bafa-083c4dad3a84"/>
                <imageExpression><![CDATA[$P{PATH_PADRAODSM} + "/" + $P{LOGOTIPO_1}]]></imageExpression>
            </image>
            <textField>
                <reportElement x="140" y="40" width="800" height="25" uuid="0282ba00-7352-4d77-bb8b-c0bb0ba0e585"/>
                <textElement verticalAlignment="Bottom">
                    <font size="16"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{TITULO}]]></textFieldExpression>
            </textField>
        </band>
    </title>
    <pageHeader>
        <band height="36">
            <line>
                <reportElement mode="Transparent" x="0" y="12" width="100" height="1" forecolor="#FFFFFF" uuid="99aed6f5-8941-4876-a95c-1ee23bd1dc0a">
                    <propertyExpression name="net.sf.jasperreports.export.xls.sheet.name"><![CDATA["Dados"]]></propertyExpression>
                </reportElement>
            </line>
        </band>
    </pageHeader>
    <columnHeader>
        <band height="16">
            <frame>
                <reportElement key="columnHeader.list1" positionType="Float" x="0" y="0" width="1352" height="16" uuid="46d7f64e-9ba3-4fa3-b6f4-f4cde887a658"/>
                <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                    <reportElement key="columnHeader.column_Codigo do candidato.title1" style="TabelaCabecalho" positionType="Float" stretchType="RelativeToTallestObject" x="0" y="0" width="104" height="16" uuid="4e458915-229a-4de2-8cdc-ca86d9721252"/>
                    <textFieldExpression><![CDATA[$P{CUSTOM_VALUES}.getValue("simpleExpression_10_")]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                    <reportElement key="columnHeader.column_Nome.title1" style="TabelaCabecalho" positionType="Float" stretchType="RelativeToTallestObject" x="104" y="0" width="104" height="16" uuid="95caf451-7a8b-41a6-a942-21cb7e3e6110"/>
                    <textFieldExpression><![CDATA[$P{CUSTOM_VALUES}.getValue("simpleExpression_12_")]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                    <reportElement key="columnHeader.column_E-mail.title1" style="TabelaCabecalho" positionType="Float" stretchType="RelativeToTallestObject" x="208" y="0" width="104" height="16" uuid="f1b3ad3f-c55d-478d-b4b5-9c73fb414477"/>
                    <textFieldExpression><![CDATA[$P{CUSTOM_VALUES}.getValue("simpleExpression_14_")]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                    <reportElement key="columnHeader.column_Idade.title1" style="TabelaCabecalho" positionType="Float" stretchType="RelativeToTallestObject" x="312" y="0" width="104" height="16" uuid="df361b4f-cad3-4770-b75c-38bfe3f1c281"/>
                    <textFieldExpression><![CDATA[$P{CUSTOM_VALUES}.getValue("simpleExpression_16_")]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                    <reportElement key="columnHeader.column_Telefone(s) Contato.title1" style="TabelaCabecalho" positionType="Float" stretchType="RelativeToTallestObject" x="416" y="0" width="104" height="16" uuid="4dc88b66-dcd6-4626-a788-7da1f70f7f6b"/>
                    <textFieldExpression><![CDATA[$P{CUSTOM_VALUES}.getValue("simpleExpression_18_")]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                    <reportElement key="columnHeader.column_Cidade e Estado.title1" style="TabelaCabecalho" positionType="Float" stretchType="RelativeToTallestObject" x="520" y="0" width="104" height="16" uuid="011ca35b-fe81-484e-aa1b-d383053452df"/>
                    <textFieldExpression><![CDATA[$P{CUSTOM_VALUES}.getValue("simpleExpression_20_")]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                    <reportElement key="columnHeader.column_Tipo de Formação 1.title1" style="TabelaCabecalho" positionType="Float" stretchType="RelativeToTallestObject" x="624" y="0" width="104" height="16" uuid="1e31895e-9fcf-4bb0-8e40-bd419c0af763"/>
                    <textFieldExpression><![CDATA[$P{CUSTOM_VALUES}.getValue("simpleExpression_22_")]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                    <reportElement key="columnHeader.column_Formação 1.title1" style="TabelaCabecalho" positionType="Float" stretchType="RelativeToTallestObject" x="728" y="0" width="104" height="16" uuid="86ed4ae1-7600-4df3-966f-401f1967e93b"/>
                    <textFieldExpression><![CDATA[$P{CUSTOM_VALUES}.getValue("simpleExpression_24_")]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                    <reportElement key="columnHeader.column_Instituição 1.title1" style="TabelaCabecalho" positionType="Float" stretchType="RelativeToTallestObject" x="832" y="0" width="104" height="16" uuid="1ce1e9dc-816a-410f-b4f0-71550c59ceeb"/>
                    <textFieldExpression><![CDATA[$P{CUSTOM_VALUES}.getValue("simpleExpression_26_")]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                    <reportElement key="columnHeader.column_Tipo de Formação 2.title1" style="TabelaCabecalho" positionType="Float" stretchType="RelativeToTallestObject" x="936" y="0" width="104" height="16" uuid="e589cd82-0758-468a-92e8-dc1a81f793ba"/>
                    <textFieldExpression><![CDATA[$P{CUSTOM_VALUES}.getValue("simpleExpression_28_")]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                    <reportElement key="columnHeader.column_Formação 2.title1" style="TabelaCabecalho" positionType="Float" stretchType="RelativeToTallestObject" x="1040" y="0" width="104" height="16" uuid="e719543b-a0e6-4f36-b265-82b0f6dbb11e"/>
                    <textFieldExpression><![CDATA[$P{CUSTOM_VALUES}.getValue("simpleExpression_30_")]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                    <reportElement key="columnHeader.column_Instituição 2.title1" style="TabelaCabecalho" positionType="Float" stretchType="RelativeToTallestObject" x="1144" y="0" width="104" height="16" uuid="d06d26bc-71a4-4444-b061-4e05bb1b7168"/>
                    <textFieldExpression><![CDATA[$P{CUSTOM_VALUES}.getValue("simpleExpression_32_")]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                    <reportElement key="columnHeader.column_Histórico profissional (2 últimas empresas).title1" style="TabelaCabecalho" positionType="Float" stretchType="RelativeToTallestObject" x="1248" y="0" width="104" height="16" uuid="0cd532cc-f4fb-47e9-aeff-cc1c61bd8a6c"/>
                    <textFieldExpression><![CDATA[$P{CUSTOM_VALUES}.getValue("simpleExpression_34_")]]></textFieldExpression>
                </textField>
            </frame>
        </band>
    </columnHeader>
    <detail>
        <band height="16">
            <frame>
                <reportElement key="detail.list1" positionType="Float" x="0" y="0" width="1352" height="16" uuid="6d7ecd54-a04a-477e-9848-3247fb8ef789"/>
                <textField isStretchWithOverflow="true" pattern="#,##0" isBlankWhenNull="true">
                    <reportElement key="detail.column_Codigo do candidato1" style="style_36_" positionType="Float" stretchType="RelativeToTallestObject" x="0" y="0" width="104" height="16" isPrintInFirstWholeBand="true" uuid="640caec8-b919-41e2-aa57-93db114b9aec"/>
                    <textElement textAlignment="Right"/>
                    <textFieldExpression><![CDATA[$F{Codigo do candidato}]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                    <reportElement key="detail.column_Nome1" style="style_36_" positionType="Float" stretchType="RelativeToTallestObject" x="104" y="0" width="104" height="16" isPrintInFirstWholeBand="true" uuid="78c8ddc7-82c5-4b8e-8ae2-a0c6be535dc7"/>
                    <textElement textAlignment="Left"/>
                    <textFieldExpression><![CDATA[$F{Nome}]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                    <reportElement key="detail.column_E-mail1" style="style_36_" positionType="Float" stretchType="RelativeToTallestObject" x="208" y="0" width="104" height="16" isPrintInFirstWholeBand="true" uuid="c687dc47-b312-45d1-8f8f-af0952d2e0ad"/>
                    <textElement textAlignment="Left"/>
                    <textFieldExpression><![CDATA[$F{E-mail}]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true" pattern="#,##0" isBlankWhenNull="true">
                    <reportElement key="detail.column_Idade1" style="style_36_" positionType="Float" stretchType="RelativeToTallestObject" x="312" y="0" width="104" height="16" isPrintInFirstWholeBand="true" uuid="74fe0b04-c84b-4a82-96e8-1fa83acf5989"/>
                    <textElement textAlignment="Right"/>
                    <textFieldExpression><![CDATA[$F{Idade}]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                    <reportElement key="detail.column_Telefone(s) Contato1" style="style_36_" positionType="Float" stretchType="RelativeToTallestObject" x="416" y="0" width="104" height="16" isPrintInFirstWholeBand="true" uuid="f25f3fbd-3d07-4865-9ba0-9196281a3536"/>
                    <textElement textAlignment="Left"/>
                    <textFieldExpression><![CDATA[$F{Telefone(s) Contato}]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                    <reportElement key="detail.column_Cidade e Estado1" style="style_36_" positionType="Float" stretchType="RelativeToTallestObject" x="520" y="0" width="104" height="16" isPrintInFirstWholeBand="true" uuid="2bef953f-ea52-4750-af77-0a8bc3efc3a0"/>
                    <textElement textAlignment="Left"/>
                    <textFieldExpression><![CDATA[$F{Cidade e Estado}]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                    <reportElement key="detail.column_Tipo de Formação 11" style="style_36_" positionType="Float" stretchType="RelativeToTallestObject" x="624" y="0" width="104" height="16" isPrintInFirstWholeBand="true" uuid="a614443a-b729-4037-943c-d16f3ba8d1e9"/>
                    <textElement textAlignment="Left"/>
                    <textFieldExpression><![CDATA[$F{Tipo de Formação 1}]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                    <reportElement key="detail.column_Formação 11" style="style_36_" positionType="Float" stretchType="RelativeToTallestObject" x="728" y="0" width="104" height="16" isPrintInFirstWholeBand="true" uuid="ac8d1676-a360-439f-925d-262df7f356e2"/>
                    <textElement textAlignment="Left"/>
                    <textFieldExpression><![CDATA[$F{Formação 1}]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                    <reportElement key="detail.column_Instituição 11" style="style_36_" positionType="Float" stretchType="RelativeToTallestObject" x="832" y="0" width="104" height="16" isPrintInFirstWholeBand="true" uuid="e35aeb7c-a96d-41d3-a1c0-1c707c890d19"/>
                    <textElement textAlignment="Left"/>
                    <textFieldExpression><![CDATA[$F{Instituição 1}]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                    <reportElement key="detail.column_Tipo de Formação 21" style="style_36_" positionType="Float" stretchType="RelativeToTallestObject" x="936" y="0" width="104" height="16" isPrintInFirstWholeBand="true" uuid="e8421e2e-5aa8-4ef5-b304-f49f708cc7df"/>
                    <textElement textAlignment="Left"/>
                    <textFieldExpression><![CDATA[$F{Tipo de Formação 2}]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                    <reportElement key="detail.column_Formação 21" style="style_36_" positionType="Float" stretchType="RelativeToTallestObject" x="1040" y="0" width="104" height="16" isPrintInFirstWholeBand="true" uuid="c43405f4-08ef-484a-aa7b-de76c850bd48"/>
                    <textElement textAlignment="Left"/>
                    <textFieldExpression><![CDATA[$F{Formação 2}]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                    <reportElement key="detail.column_Instituição 21" style="style_36_" positionType="Float" stretchType="RelativeToTallestObject" x="1144" y="0" width="104" height="16" isPrintInFirstWholeBand="true" uuid="3f1903a0-30a2-430b-bd57-7c8ce1211a82"/>
                    <textElement textAlignment="Left"/>
                    <textFieldExpression><![CDATA[$F{Instituição 2}]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                    <reportElement key="detail.column_Histórico profissional (2 últimas empresas)1" style="style_36_" positionType="Float" stretchType="RelativeToTallestObject" x="1248" y="0" width="104" height="16" isPrintInFirstWholeBand="true" uuid="f07d5d11-9422-4c35-b8f5-3904982ca456"/>
                    <textElement textAlignment="Left"/>
                    <textFieldExpression><![CDATA[$F{Histórico profissional (2 últimas empresas)}]]></textFieldExpression>
                </textField>
            </frame>
        </band>
    </detail>
    <pageFooter>
        <band height="38" splitType="Stretch"/>
    </pageFooter>
    <summary>
        <band height="46" splitType="Stretch">
            <property name="local_mesure_unitheight" value="pixel"/>
            <textField pattern="">
                <reportElement x="0" y="34" width="560" height="12" uuid="4ca54330-fb17-4ef6-8d18-3ceace2083b9"/>
                <textElement textAlignment="Left"/>
                <textFieldExpression><![CDATA["Relatório gerado por VAGAS Tecnologia de Software em " + new SimpleDateFormat("dd/MM/yy HH:mm:ss").format(new java.util.Date())]]></textFieldExpression>
            </textField>
        </band>
    </summary>
</jasperReport>

diegoqueres
  • 149
  • 1
  • 13
  • I have answered this questions but I think you should consider to review your old questions to see if there are some answers on them that should be accepted, see the [tour](http://stackoverflow.com/tour) to learn what [accepted](http://stackoverflow.com/help/accepted-answer) answer is. – Petter Friberg Aug 30 '16 at 00:23
  • Ok. I managed to make some progress, but still can not solve the problem. You can see my answer. Thank you! – diegoqueres Aug 30 '16 at 14:53

2 Answers2

2

You are saving the compiled version of the report that is not filled, the JasperDesign object not the JasperPrint

You should use report.toJasperPrint()

Example

JRSaver.saveObject(report.toJasperPrint(),  "fullPath/yourReport.jrprint");

To reload your filled report use:

JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(new java.io.FileInputStream("fullPath/yourReport.jrprint"));

And to export it use the JasperExportManager or one of the export class example JRXlsExporter

Graham
  • 7,431
  • 18
  • 59
  • 84
Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
1

FIXED PROBLEM I find the solution for the problem. The problem was the dependence of DYNAMIC REPORTS and CUSTOM_VALUES. When i use the compiled report, it did not find these values.

So, I need modify every place where have this kind of dependence and make the report uses native expressions of Jasper Reports.

I could understand with the explanations of ricardo in this topic: http://www.dynamicreports.org/forum/viewtopic.php?f=1&t=579&p=1983&hilit=custom_values&sid=8757448603905e175044b8637780d608#p1983

So, i use this object to generate Jasper native expressions: net.sf.dynamicreports.report.builder.DynamicReports.exp. I fix the .setTitle to write in jasper syntax: column.setTitle(exp.jasperSyntaxText("Some title"));

Fixing this method:

public List<TextColumnBuilder> getDRColumnsFromRecordset(ResultSet rs) throws SQLException {
        ResultSetMetaData rsmd = rs.getMetaData();
        List<TextColumnBuilder> lsColumns = new ArrayList<>();
        TextColumnBuilder column = null;

        for (int i = 1; i <= rsmd.getColumnCount(); i++) {
            switch (rsmd.getColumnType(i)) {
                case Types.VARCHAR:
                case Types.NVARCHAR:
                    column = col.column(rsmd.getColumnName(i), rsmd.getColumnName(i), type.stringType());
                    break;

                case Types.INTEGER:
                    column = col.column(rsmd.getColumnName(i), rsmd.getColumnName(i), type.integerType());
                    break;

                default:
                    column = col.column(rsmd.getColumnName(i), rsmd.getColumnName(i), type.stringType());
                    break;

            }
            column.setMinColumns(10);
            column.addProperty(JasperProperty.PRINT_KEEP_FULL_TEXT, exp.jasperSyntax("\"true\""));
            column.addProperty(JasperProperty.EXPORT_XLS_WRAP_TEXT, exp.jasperSyntax("\"true\""));
            column.setTitle(exp.jasperSyntaxText(rsmd.getColumnName(i)));

            lsColumns.add(column);

        }

        return lsColumns;

    }

When i use col.column("Column name", "Column name", type.stringType()); I get in column name ( .jasper ): $P{CUSTOM_VALUES}.getValue("simpleExpression_10_") Because that, column header was blank. In the second time, jasper doesn't have CUSTOM_VALUES to fill...

When i use col.setTitle(exp.jasperSyntaxText("Column name")); I get in column name ( .jasper ): "Column name"

Thanks Petter for your attention! :-)

diegoqueres
  • 149
  • 1
  • 13