Search code examples
jasper-reportsireport

Displaying object as image inside a list component


Problem

I have to display an object as an image inside a list component based on a particular count (intNote). While using an image path from specific location the images are displayed.

Question

How can I display an object as an image inside a list component?

Source

The JRXML:

<subDataset name="Q2">
        <field name="strVert" class="java.awt.Image"/>      
</subDataset>

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

<componentElement>
    <reportElement x="130" y="72" width="25" height="35"/>
    <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="Horizontal" ignoreWidth="true">
        <datasetRun subDataset="Q2">
            <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource($F{intNote})]]></dataSourceExpression>
        </datasetRun>
        <jr:listContents height="35" width="25">
            <image isUsingCache="false">
                <reportElement x="3" y="10" width="16" height="17" forecolor="#FFFFFF"/>
                <graphicElement>
                    <pen lineWidth="1.25"/>
                </graphicElement>
                <imageExpression class="java.awt.Image"><![CDATA[$F{strVert}]]></imageExpression>
            </image>
        </jr:listContents>
    </jr:list>
</componentElement>

Thank you.


Solution

  • In jasper you can display images by putting the current image location instead of the varible intNote.it is the only possible way to get the image in the output.