<?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="TestingImage" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isIgnorePagination="true" uuid="5470e3fc-1c9c-4841-8814-e3a935fa6684"> <property name="ireport.zoom" value="1.0"/><property name="ireport.x" value="0"/><property name="ireport.y" value="229"/><style name="table"><box><pen lineWidth="1.0" lineColor="#000000"/></box></style><style name="table_TH" mode="Opaque" backcolor="#F0F8FF"><box><pen lineWidth="0.5" lineColor="#000000"/></box></style><style name="table_CH" mode="Opaque" backcolor="#BFE1FF"><box><pen lineWidth="0.5" lineColor="#000000"/></box></style><style name="table_TD" mode="Opaque" backcolor="#FFFFFF"><box><pen lineWidth="0.5" lineColor="#000000"/></box></style><style name="Table_TH" mode="Opaque" backcolor="#F0F8FF"><box><pen lineWidth="0.5" lineColor="#000000"/><topPen lineWidth="0.5" lineColor="#000000"/><leftPen lineWidth="0.5" lineColor="#000000"/><bottomPen lineWidth="0.5" lineColor="#000000"/<rightPen lineWidth="0.5" lineColor="#000000"/></box></style><style name="Table_CH" mode="Opaque" backcolor="#BFE1FF"><box><pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<subDataset name="ImageDemoDataset" uuid="47414685-b792-4a30-9b14-fc32127ad3cc">
<parameter name="lastname" class="java.lang.String">
<defaultValueExpression><![CDATA[$F{picture}]]></defaultValueExpression>
</parameter>
<parameter name="firstname" class="java.lang.String">
<defaultValueExpression><![CDATA[$F{firstname}]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[]]>
</queryString>
<field name="firstname" class="java.lang.String"/>
<field name="lastname" class="java.lang.String"/>
<field name="email" class="java.lang.String"/>
<field name="phone_number" class="java.lang.String"/>
<field name="picture" class="java.lang.String"/>
<variable name="imagePath" class="java.lang.String" resetType="None">
<variableExpression><![CDATA[$F{picture}]]></variableExpression>
</variable>
</subDataset>
<parameter name="ImageDataSource" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
<queryString>
<![CDATA[]]>
</queryString>
<variable name="varImage" class="java.lang.String" resetType="None"/>
<detail>
<band height="364" splitType="Stretch">
<componentElement>
<reportElement x="18" y="0" width="474" height="216" uuid="771aa5d8-1470-4fd9-b062-a913b6014f19">
<property name="net.sf.jasperreports.export.headertoolbar.table.name" value=""/>
</reportElement>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" whenNoDataType="AllSectionsNoDetail">
<datasetRun subDataset="ImageDemoDataset" uuid="c4a063af-d8d1-41c4-98bf-660a9eab651e">
<dataSourceExpression><![CDATA[$P{ImageDataSource}]]></dataSourceExpression>
<returnValue fromVariable="imagePath" toVariable="varImage"/>
</datasetRun>
<jr:column width="70" uuid="6aa96500-79ab-4b8b-aa5f-0c9dbc22638f">
<jr:detailCell height="30" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="70" height="30" uuid="9528bbd1-627c-424c-a3f0-872f92799c94"/>
<textFieldExpression><![CDATA[$F{firstname}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90" uuid="ba88fb55-d423-4d1e-99a1-b81c44f6e65a">
<jr:detailCell height="30" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="90" height="30" uuid="5c85fd56-54ba-4d22-a3e4-adcdbbbc2b4f"/>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{lastname} ]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="100" uuid="29524685-b68a-4906-be22-50b0acacba7d">
<jr:detailCell height="30" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="100" height="30" uuid="9dacce68-21ca-4bcc-b9cb-bad1b3661611"/>
<textFieldExpression><![CDATA[$F{email}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="94" uuid="4bb9635f-4173-4c5b-95ce-5a12a2332ea1">
<jr:detailCell height="30" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="94" height="30" uuid="8c6c58b1-d3fd-4fad-995a-caaaea6afe8e"/>
<textFieldExpression><![CDATA[$F{phone_number}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="100" uuid="b500de9f-6abf-41b8-9e5d-d408b94d32ce">
<jr:detailCell height="30" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="100" height="30" uuid="0e6a1e56-974f-41a3-af08-0cf5b832b573"/>
<textFieldExpression><![CDATA[$F{picture}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
<image scaleImage="FillFrame" hAlign="Center" vAlign="Middle">
<reportElement x="48" y="266" width="100" height="98" uuid="290e1eb9-3a18-4a65-93d4-d155b98ce964">
<printWhenExpression><![CDATA[!$V{varImage}.equalsIgnoreCase("null")]]></printWhenExpression>
</reportElement>
<imageExpression><![CDATA["C:\\Users\\jigpra\\Pictures\\"+$V{varImage}]]></imageExpression>
</image>
<staticText>
<reportElement x="48" y="231" width="100" height="20" uuid="32fd136d-d7c4-4256-be6c-e9ad7d5f7592"/>
<textElement>
<font size="12"/>
</textElement>
<text><![CDATA[$V{varImage}]]></text>
</staticText>
</band>
</detail>
I want to use Table dataset Field/parameter in Main report. I added data of collection in table to show upin this data I have one value is image for every column. I want to get that Image name (currently in collection dataset I pass name of image).
How can I retrieve picture field name in main report?
You do not see the image because it does not have the proper Evaluation Time
- it needs to be Band
in your case.
The staticText
does not support such setting, you need to convert it to a textField
and set the same for the Evaluation Time
property.
But even with the above suggestions you would still see the last value from your ImageDemoDataset
subDataset
. It is fine if that is what you want.
But if you want to display an image for each record in your subDataset
, you would have to do it inside the table. If spacing was the issue, you could create a columnGroup
and place the image in the groupFooter
, isolating it below your main data.
EDIT: It seems that what you want is actually simpler and should not involve variables. You just need to reiterate over the same data source. This can be done in 2 ways:
(1). Using the original ImageDataSource
parameter:
<parameter name="ImageDataSource" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
have the table datasetRun's expression like so:
<dataSourceExpression><![CDATA[$P{ImageDataSource}.cloneDataSource()]]></dataSourceExpression>
Then create a list component under the table, with the same subDataset
you used for the table and the initial data source expression:
<dataSourceExpression><![CDATA[$P{ImageDataSource}]]></dataSourceExpression>
and set its Print Order
to Horizontal
in the List tab from the list component properties. Make sure you also specify the Cell Width
to be small enough to allow repeating items to flow horizontally.
Cloning the dataSource for the table will ensure that the table will not exhaust it, so that the list component will still be able to iterate over it.
(2). Instead of passing the JRBeanCollectionDataSource
as a parameter, pass just the collection you created it with and have a parameter for that. This way you do not need to clone the dataSource anymore:
<parameter name="ImageCollection" class="java.util.Collection"/>
Then have the table datasetRun's expression like so:
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{ImageCollection})]]></dataSourceExpression>
Then create a list with the same subDataset
you used for the table and use the dataSourceExpression
from above. You should set up the list in the same way as in (1).