Jump to content

DATA MISSING IN LIST CONTENTS WHEN EXPORTED AS HTML


pasose2675

Recommended Posts

Hi, I have a list of objects let's say countries list, Each country object has id and list of cities. I'm passing the countries list as datasource and using subDataset to traverse the inner list. This is working fine with pdf export. But in html export the list contents data is missing. I've added a detail band above the list contents with displaying id and a footer.

The id is coming and the footer is also coming and the space the list contents might take is also there but the data is not showing up. Am I missing something, Please Help.

I'm using this <dependency> <groupId>net.sf.jasperreports</groupId> <artifactId>jasperreports</artifactId> <version>6.19.1</version> </dependency> for report generation.

This is my .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="classic" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="30" rightMargin="30" topMargin="20"

    bottomMargin="20" uuid="487b678d-2fac-49b4-b799-5625f2f85536">

    <subDataset name="dataset1">

        <field name="city" class="java.lang.String">

            <fieldDescription>

                <![CDATA[_THIS]]>

            </fieldDescription>

        </field>

    </subDataset>

    <field name="id" class="java.lang.Integer" />

    <field name="cities" class="java.util.Collection" />

    <detail>

        <band height="1" splitType="Stretch">

            <componentElement>

                <reportElement x="0" y="0" width="0" height="1" />

                <jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components"

                    xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd"

                    printOrder="Vertical">

                    <datasetRun subDataset="dataset1">

                        <dataSourceExpression>

                            <![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{cities})]]>

                        </dataSourceExpression>

                    </datasetRun>

                    <jr:listContents height="71" width="535">

                        <staticText>

                            <reportElement key="staticText-15" positionType="Float" x="3" y="34" width="145" height="17" forecolor="#000000" backcolor="#FFFFFF" uuid="5c71ee28-f0e2-4748-a2c3-dd326a2c26eb" />

                            <box>

                                <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000" />

                                <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000" />

                                <bottomPen lineWidth="0.0" lineColor="#000000" />

                                <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000" />

                            </box>

                            <textElement textAlignment="Right" verticalAlignment="Top"><font size="12"/></textElement>

                            <text><![CDATA[Name 1 :]]></text>

                        </staticText>

                        <staticText>

                            <reportElement key="staticText-16" positionType="Float" x="3" y="17" width="145" height="17" forecolor="#000000" backcolor="#FFFFFF" uuid="c1f3e3b9-dd46-4155-b64f-e62c8ca413fd" />

                            <box>

                                <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000" />

                                <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000" />

                                <bottomPen lineWidth="0.0" lineColor="#000000" />

                                <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000" />

                            </box>

                            <textElement textAlignment="Right" verticalAlignment="Top"><font size="12" /></textElement>

                            <text><![CDATA[Name 2 :]]></text>

                        </staticText>

                        <staticText>

                            <reportElement key="staticText-17" positionType="Float" x="3" y="0" width="145" height="17" forecolor="#000000" backcolor="#FFFFFF" uuid="79160151-dcb9-4bf7-b1ba-1b55f0eaa5e1" />

                            <box>

                                <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000" />

                                <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000" />

                                <bottomPen lineWidth="0.0" lineColor="#000000" />

                                <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000" />

                            </box>

                            <textElement textAlignment="Right" verticalAlignment="Top"><font size="12" /></textElement>

                            <text><![CDATA[Name 3:]]></text>

                        </staticText>

                        <textField isBlankWhenNull="false">

                            <reportElement key="textField-12" x="154" y="0" width="381" height="17" uuid="0f8e8324-4f09-4e9f-a508-ab82c44bfe4c" />

                            <textElement><font size="12" /></textElement>

                            <textFieldExpression><![CDATA[$F{city}]]></textFieldExpression>

                        </textField>

                        <textField isBlankWhenNull="false">

                            <reportElement key="textField-13" x="154" y="34" width="381" height="17" uuid="b382a873-476a-44c6-aa55-2a699f4fd861" />

                            <textElement><font size="12" /></textElement>

                            <textFieldExpression><![CDATA[$F{city}]]></textFieldExpression>

                        </textField>

                        <textField isBlankWhenNull="false">

                            <reportElement key="textField-14" x="154" y="17" width="381" height="17" uuid="4c55d64b-e5df-44de-ae7d-09884603cfbf" />

                            <textElement><font size="12" /></textElement>

                            <textFieldExpression><![CDATA[$F{city}]]></textFieldExpression>

                        </textField>

                    </jr:listContents>

                </jr:list>

            </componentElement>

        </band>

    </detail>

</jasperReport>

The generation method - 

jasperReport = JasperCompileManager.compileReport(inputStream);

Map<String, Object> parameters = new HashMap<>();

Collection<BeanWithList> coll = new ArrayList<BeanWithList>();

coll.add(new BeanWithList(Arrays.asList("London", "Paris"), 1));

coll.add(new BeanWithList(Arrays.asList("London", "Madrid", "Moscow"), 2));

coll.add(new BeanWithList(Arrays.asList("Rome"), 3));

JRDataSource dataSource = new JRBeanCollectionDataSource(coll);

JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, dataSource);

OutputStream outputStream = encryptFile(fileName, true);

export(extension, jasperPrint, outputStream, fileName);

outputStream.close();

and the Export method -

if (extension.equals(".html")) {

HtmlExporter exporter = new HtmlExporter();

exporter.setExporterInput(new SimpleExporterInput(jasperPrint));

exporter.setExporterOutput(new SimpleHtmlExporterOutput(outputStream));

exporter.exportReport();

}

I want it to look something like this converted-file.png.595d8ff49b171cc67c2aa00ac0bc1bd5.png

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

  • 2 weeks later...

Your JRXML and data binding seems to have some issues. If you are testing out this functionality, I would suggest you to create simpler example. There is no need to repeat the Static text for each time, rather you can create a textField with concatenated text for "Name " + $F{id} to have Id displayed for each city name.

Please refer to below two examples. I don't see any issue with your HtmlExporter code, as you are creating Input and Output streams fine. 

You can also try with JasperExportManager.exportReportToHtmlFile method.


https://www.tabnine.com/code/java/classes/net.sf.jasperreports.engine.export.HtmlExporter
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...