Reputation: 61
I have a main report and subreport, and I pass a parameter to subreport as inputstream. I will use this parameter as a logo(image) in my subreport header. If I add the image to subreport and use this parameter, subreport shows only first record of my datasource and the image. If I do not use this image, my subreport lists all records of my datasource. I tried to put the image in detail, header, and title, but it did not work. If I use an image directly from subreport, it works well, but I need to send this parameter(filepath) from Java.
What can be the problem?
Edit: I provide some code.
Main report:
<?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="e-BordroIsciToplu" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="a3c2690b-2af8-4210-8775-cb69cd6557f7">
<property name="ireport.zoom" value="1.5394743546921228"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<property name="ireport.background.image.properties" value="true,true,0.25,138,273,0,0,386,161"/>
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["W:\\Projects\\modules\\common\\src\\resources\\report\\templates\\"]]></defaultValueExpression>
</parameter>
<parameter name="ANTET" class="java.io.InputStream"/>
<parameter name="AY" class="java.lang.String"/>
<field name="topluInfo" class="java.util.List"/>
<detail>
<band height="109" splitType="Stretch">
<subreport runToBottom="false">
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="0" y="0" width="533" height="100" uuid="cd6571c7-c8da-4120-868f-82999376c3d3"/>
<parametersMapExpression><![CDATA[]]></parametersMapExpression>
<subreportParameter name="SUBREPORT_DIR">
<subreportParameterExpression><![CDATA[]]> </subreportParameterExpression>
</subreportParameter>
<subreportParameter name="AY">
<subreportParameterExpression><![CDATA[$P{AY}]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="ANTET">
<subreportParameterExpression><![CDATA[$P{ANTET}]]></subreportParameterExpression>
</subreportParameter>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{topluInfo})]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "e-topluSubreportTest.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
</jasperReport>
Subreport:
<?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="e-topluSubreport" language="groovy" pageWidth="595" pageHeight="842" columnWidth="545" leftMargin="20" rightMargin="30" topMargin="20" bottomMargin="20" uuid="a3c2690b-2af8-4210-8775-cb69cd6557f7">
<property name="ireport.zoom" value="1.5394743546921228"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<property name="ireport.background.image.properties" value="true,true,0.25,138,273,0,0,386,161"/>
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["W:\\Projects\\modules\\common\\src\\resources\\report\\templates\\"]]></defaultValueExpression>
</parameter>
<parameter name="ANTET" class="java.io.InputStream"/>
<parameter name="AY" class="java.lang.String"/>
<detail>
<band height="139" splitType="Stretch">
<staticText>
<reportElement x="5" y="105" width="185" height="15" uuid="023f69c4-13a4-419e-b64b-d41da9f937fa"/>
<box>
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement verticalAlignment="Middle">
<font size="8" isBold="true" pdfEncoding="Cp1254"/>
</textElement>
<text><![CDATA[ BORDRO TÜRÜ ]]></text>
</staticText>
<staticText>
<reportElement x="5" y="120" width="185" height="15" uuid="e7aac3af-4436-4488-9b00-e93ed875119f"/>
<box>
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement verticalAlignment="Middle">
<font size="8" isBold="true" pdfEncoding="Cp1254"/>
</textElement>
<text><![CDATA[ PARA BİRİMİ]]></text>
</staticText>
<staticText>
<reportElement x="5" y="79" width="500" height="15" uuid="55328d4d-8ce4-44aa-9217-405be02338b6"/>
<box>
<pen lineWidth="0.0"/>
<topPen lineWidth="0.0"/>
<leftPen lineWidth="0.0"/>
<bottomPen lineWidth="0.0"/>
<rightPen lineWidth="0.0"/>
</box>
<textElement verticalAlignment="Middle">
<font size="8" isBold="true" pdfEncoding="Cp1254"/>
</textElement>
<text><![CDATA[* test]]></text>
</staticText>
<image>
<reportElement x="5" y="23" width="101" height="35" uuid="057a515d-61a7-4f54-9c5e-234acaede0e5"/>
<imageExpression><![CDATA[$P{ANTET}]]></imageExpression>
</image>
</band>
<band height="50"/>
</detail>
</jasperReport>
Upvotes: 1
Views: 1663
Reputation: 5093
Your original report showed the image only for the first record because an InputStream can only be read once. If you use a single InputStream instance for an image element that prints several times, it will work fine the first time but then it won't be able to read any data from the stream.
There are two things that you can do. One is to pass the image data as a byte array instead of a stream.
The second is to set isUsingCache="true"
for the image element. This would cache the image object when first rendering the element and then use the cached image when the image element is printed again.
The second approach would be better from a performance point of view since the image data would not be read several times. You can also combine the solutions by passing the image data as a byte array and setting the isUsingCache flag as well.
Upvotes: 3
Reputation: 61
I found the solution. I remove the image from the subreport and put the image in the page header of the main report. It solved my problem but I am still wondering the previous problem why it shows only one record. Thanks for your comments and valuable time.
Upvotes: 0