Jump to content
We've recently updated our Privacy Statement, available here ×

Subreport in a list


ejhellerattc

Recommended Posts

Our database is structured in such a way that part of it is a list of items. Each of the items in this list are associated with additional lists of items. So, for items in table A, they have references (through association tables) to tables B, C and D. I have created a report that, when passed an appropriate key reference from table A, reports the values from tables B, C and D for that item. Since the data from tables B, C and D are only part of the information needed to be presented, what I was hoping to do was create a master report that used a list to loop through the items in table A (using a subdataset) and pass the key to the subreport which would then generate the subreport within the list context. The list is set up correctly, since I can print the key within the list. The JRXML files compile fine and no run time errors.

I have noticed a couple of things:

1) The subreport does not appear to be getting an updated key. The value printed for the passed value of the key is always the first record. Thus the SQL always returns the first record.

2) If the generated size of the subreport is larger than the allocated space for the list entry, nothing is printed. This does not follow with the usual behavior of the subreport expanding as needed. Is there a parameter for the list component to allow the list to expand? I have written other reports where the subreport element is 1 pixel high (to get many on the master report) and the subreports display correctly.

Any thoughts? I have included samples of the primary and sub reports.

Thanks,

Ed.

Code:
Primary 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="SystemConfigurationReport" language="groovy" pageWidth="792" pageHeight="612" orientation="Landscape" columnWidth="752" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">	<property name="ireport.zoom" value="1.5"/>	<property name="ireport.x" value="0"/>	<property name="ireport.y" value="0"/>	<subDataset name="Categories">		<parameter name="SUBREPORT_DIR" class="java.lang.String"/>		<queryString>			<![CDATA[select pk as CategoryPK from CATEGORY]]>		</queryString>		<field name="CATEGORYPK" class="java.lang.Integer"/>	</subDataset>	<parameter name="JasperCommonDirectory" class="java.lang.String" isForPrompting="false">		<defaultValueExpression><![CDATA["c:\\reports"]]></defaultValueExpression>	</parameter>	<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">		<defaultValueExpression><![CDATA["E:\\products\\reports\\src\\JasperReports"]]></defaultValueExpression>	</parameter>	<queryString>		<![CDATA[select description from SYSTEM]]>	</queryString>	<field name="DESCRIPTION" class="java.lang.String"/>	<background>		<band splitType="Stretch"/>	</background>	<pageHeader>		<band height="37">			<staticText>				<reportElement x="1" y="13" width="752" height="24"/>				<textElement textAlignment="Center" markup="none"/>				<text><![CDATA[system Configuration]]></text>			</staticText>		</band>	</pageHeader>	<columnHeader>		<band splitType="Stretch"/>	</columnHeader>	<detail>		<band height="261" splitType="Stretch">			<staticText>				<reportElement positionType="Float" mode="Opaque" x="1" y="42" width="752" height="15" forecolor="#FFFFFF" backcolor="#0033FF"/>				<box>					<pen lineWidth="0.0"/>					<topPen lineWidth="1.0" lineStyle="Double" lineColor="#0033FF"/>					<leftPen lineWidth="0.0"/>					<bottomPen lineWidth="0.0"/>					<rightPen lineWidth="0.0"/>				</box>				<textElement verticalAlignment="Middle">					<font size="10" isBold="true"/>				</textElement>				<text><![CDATA[Categories]]></text>			</staticText>			<componentElement>				<reportElement positionType="Float" x="3" y="63" width="752" height="190"/>				<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="Categories">						<datasetParameter name="SUBREPORT_DIR">							<datasetParameterExpression><![CDATA[$P{SUBREPORT_DIR}]]></datasetParameterExpression>						</datasetParameter>					</datasetRun>					<jr:listContents height="190" width="752">						<frame>							<reportElement positionType="Float" x="2" y="2" width="746" height="48"/>							<textField>								<reportElement positionType="Float" x="95" y="0" width="100" height="20"/>								<textElement/>								<textFieldExpression class="java.lang.Integer"><![CDATA[$F{CATEGORYPK}]]></textFieldExpression>							</textField>							<subreport isUsingCache="false">								<reportElement positionType="Float" x="0" y="20" width="729" height="28"/>								<subreportParameter name="CategoryPK">									<subreportParameterExpression><![CDATA[$F{CATEGORYPK}]]></subreportParameterExpression>								</subreportParameter>								<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>								<subreportExpression class="java.lang.String"><![CDATA[$P{SUBREPORT_DIR} + "\\SubReport.jasper"]]></subreportExpression>							</subreport>							<staticText>								<reportElement x="0" y="0" width="95" height="20"/>								<textElement/>								<text><![CDATA[Category PK = ]]></text>							</staticText>						</frame>					</jr:listContents>				</jr:list>			</componentElement>		</band>	</detail>	<pageFooter>		<band height="18" splitType="Stretch">			<textField pattern="MMMMM dd, yyyy HH:mm:ss">				<reportElement x="0" y="0" width="168" height="14"/>				<textElement/>				<textFieldExpression class="java.util.Date"><![CDATA[new java.util.Date()]]></textFieldExpression>			</textField>			<textField>				<reportElement x="632" y="1" width="80" height="14"/>				<textElement textAlignment="Right"/>				<textFieldExpression class="java.lang.String"><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>			</textField>			<textField evaluationTime="Report">				<reportElement x="712" y="1" width="40" height="14"/>				<textElement/>				<textFieldExpression class="java.lang.String"><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>			</textField>		</band>	</pageFooter>	<summary>		<band height="69"/>	</summary></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="CategoriesReport" language="groovy" pageWidth="612" pageHeight="792" columnWidth="612" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">	<property name="ireport.zoom" value="1.0"/>	<property name="ireport.x" value="0"/>	<property name="ireport.y" value="0"/>	<parameter name="CategoryPK" class="java.lang.Integer">		<defaultValueExpression><![CDATA[1]]></defaultValueExpression>	</parameter>	<queryString>		<![CDATA[select pk, name from CATEGORYWhere pk = $P!{CategoryPK}]]>	</queryString>	<field name="PK" class="java.math.BigDecimal"/>	<field name="NAME" class="java.lang.String"/>	<detail>		<band height="64" splitType="Stretch">			<textField>				<reportElement mode="Opaque" x="73" y="0" width="192" height="20" forecolor="#000000" backcolor="#C9D8FF"/>				<textElement textAlignment="Left" verticalAlignment="Middle" rotation="None" lineSpacing="Single" markup="none">					<font fontName="SansSerif" size="10" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica" pdfEncoding="Cp1252" isPdfEmbedded="false"/>				</textElement>				<textFieldExpression class="java.lang.String"><![CDATA[$F{NAME}]]></textFieldExpression>			</textField>			<staticText>				<reportElement mode="Opaque" x="0" y="0" width="73" height="20" backcolor="#C9D8FF"/>				<textElement verticalAlignment="Middle"/>				<text><![CDATA[Category Name:]]></text>			</staticText>			<textField>				<reportElement x="267" y="0" width="100" height="20"/>				<textElement/>				<textFieldExpression class="java.lang.Integer"><![CDATA[$P{CategoryPK}]]></textFieldExpression>			</textField>		</band>	</detail></jasperReport>
Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Some food for thought.

I modified the query in the subreport to replace the passed in parameter (CategoryPK) with a fixed value (4). The subreport is displayed, but the reported value of the passed in parameter is always 0. When is the value passed to the subreport evaluated? Is it evaluated for each iteration of the list query or when the subreport instance is created? The latter assumes that the subreport instance is created when the primary report is run and referenced for each iteration of the list and not created for each iteration.

Thanks,

Ed.

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...