我正在使用xml数据源并将xml数据传递给ireport中的表。我有一个要求,其中xml标记“amount”的值需要格式化并传递给表。我创建了“amount”作为参数并从java类传递它,但amount列下的表的所有行都打印相同的值。
我所做的是:
1. Created a parameter in the subdataset
2. Edited the table datasource and added amount in the parameters tab
请参阅.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="DCU_New_template" language="groovy" pageWidth="612" pageHeight="792" columnWidth="540" leftMargin="36" rightMargin="36" topMargin="36" bottomMargin="36" uuid="af5e4276-6e2e-4357-8845-dc8f7d22f777">
<subDataset name="datasetOne" uuid="ea5d2d96-84ca-46ca-a811-d75e3935428f">
<parameter name="amount" class="net.sf.jasperreports.engine.JREmptyDataSource" isForPrompting="false"/>
<queryString language="xPath">
<![CDATA[/sendDetail/results/]]>
</queryString>
<field name="results" class="java.lang.String">
<fieldDescription><![CDATA[child::text()]]></fieldDescription>
</field>
<field name="effDate" class="java.lang.String">
<fieldDescription><![CDATA[effDate]]></fieldDescription>
</field>
<field name="period" class="java.lang.String">
<fieldDescription><![CDATA[period]]></fieldDescription>
</field>
<field name="amount" class="java.lang.String">
<fieldDescription><![CDATA[amount]]></fieldDescription>
</field>
<field name="totalAmount" class="java.lang.String">
<fieldDescription><![CDATA[totalAmount]]></fieldDescription>
</field>
<field name="description" class="java.lang.String">
<fieldDescription><![CDATA[description]]></fieldDescription>
</field>
<field name="policyNbr" class="java.lang.String"/>
<field name="accountId" class="java.lang.String"/>
<field name="frequency" class="java.lang.String">
<fieldDescription><![CDATA[frequency]]></fieldDescription>
</field>
<field name="lastName" class="java.lang.String">
<fieldDescription><![CDATA[lastName]]></fieldDescription>
</field>
<field name="firstName" class="java.lang.String">
<fieldDescription><![CDATA[firstName]]></fieldDescription>
</field>
</subDataset>
<parameter name="path" class="java.lang.String" isForPrompting="false"/>
<parameter name="policyNbr" class="java.lang.String" isForPrompting="false"/>
<parameter name="accountId" class="java.lang.String" isForPrompting="false"/>
<parameter name="firstName" class="java.lang.String" isForPrompting="false"/>
<parameter name="lastName" class="java.lang.String" isForPrompting="false"/>
<parameter name="frequency" class="java.lang.String" isForPrompting="false"/>
<parameter name="effDate" class="java.lang.String" isForPrompting="false"/>
<parameter name="amount" class="java.lang.String" isForPrompting="false"/>
<queryString language="xPath">
<![CDATA[/]]>
</queryString>
<field name="effDate" class="java.lang.String">
<fieldDescription><![CDATA[effDate]]></fieldDescription>
</field>
<field name="period" class="java.lang.String">
<fieldDescription><![CDATA[period]]></fieldDescription>
</field>
<field name="amount" class="java.lang.String">
<fieldDescription><![CDATA[amount]]></fieldDescription>
</field>
<field name="totalAmount" class="java.lang.String">
<fieldDescription><![CDATA[totalAmount]]></fieldDescription>
</field>
<field name="description" class="java.lang.String">
<fieldDescription><![CDATA[description]]></fieldDescription>
</field>
<field name="firstName" class="java.lang.String">
<fieldDescription><![CDATA[firstName]]></fieldDescription>
</field>
<field name="lastName" class="java.lang.String">
<fieldDescription><![CDATA[lastName]]></fieldDescription>
</field>
<field name="accountId" class="java.lang.String"/>
<field name="policyNbr" class="java.lang.String"/>
<field name="frequency" class="java.lang.String">
<fieldDescription><![CDATA[frequency]]></fieldDescription>
</field>
<title>
<band height="285">
<staticText>
<reportElement uuid="68f99313-089f-4856-9b3b-1de9b8141c8e" x="381" y="98" width="130" height="16"/>
<textElement verticalAlignment="Middle">
<font fontName="Calibri" size="13" isBold="true"/>
</textElement>
<text><![CDATA[Enrollee Address]]></text>
</staticText>
<staticText>
<reportElement uuid="68f99313-089f-4856-9b3b-1de9b8141c8e" x="224" y="98" width="125" height="16"/>
<textElement verticalAlignment="Middle">
<font fontName="Calibri" size="13" isBold="true"/>
</textElement>
<text><![CDATA[Current Amount Due:]]></text>
</staticText>
<staticText>
<reportElement uuid="68f99313-089f-4856-9b3b-1de9b8141c8e" x="0" y="99" width="119" height="16"/>
<textElement verticalAlignment="Middle">
<font fontName="Calibri" size="13" isBold="true"/>
</textElement>
<text><![CDATA[Billing Information:]]></text>
</staticText>
<staticText>
<reportElement uuid="68f99313-089f-4856-9b3b-1de9b8141c8e" x="414" y="48" width="126" height="15"/>
<textElement>
<font fontName="Calibri" size="9" isBold="false"/>
</textElement>
<text><![CDATA[deltadentalins.com/aarp]]></text>
</staticText>
<staticText>
<reportElement uuid="68f99313-089f-4856-9b3b-1de9b8141c8e" x="0" y="222" width="157" height="16"/>
<textElement verticalAlignment="Middle">
<font fontName="Calibri" size="13" isBold="true"/>
</textElement>
<text><![CDATA[Recent Transaction History]]></text>
</staticText>
<staticText>
<reportElement uuid="68f99313-089f-4856-9b3b-1de9b8141c8e" x="0" y="182" width="119" height="16"/>
<textElement verticalAlignment="Middle">
<font fontName="Calibri" size="13" isBold="false"/>
</textElement>
<text><![CDATA[Billing Frequency:]]></text>
</staticText>
<staticText>
<reportElement uuid="68f99313-089f-4856-9b3b-1de9b8141c8e" x="0" y="144" width="119" height="16"/>
<textElement verticalAlignment="Middle">
<font fontName="Calibri" size="13" isBold="false"/>
</textElement>
<text><![CDATA[Account Number:]]></text>
</staticText>
<staticText>
<reportElement uuid="68f99313-089f-4856-9b3b-1de9b8141c8e" x="157" y="254" width="38" height="16"/>
<textElement verticalAlignment="Middle">
<font fontName="Calibri" size="13" isBold="false"/>
</textElement>
<text><![CDATA[From:]]></text>
</staticText>
<staticText>
<reportElement uuid="68f99313-089f-4856-9b3b-1de9b8141c8e" x="224" y="125" width="119" height="16"/>
<textElement verticalAlignment="Middle">
<font fontName="Calibri" size="13" isBold="false"/>
</textElement>
<text><![CDATA[Amount Due]]></text>
</staticText>
<staticText>
<reportElement uuid="68f99313-089f-4856-9b3b-1de9b8141c8e" x="381" y="163" width="159" height="16"/>
<textElement verticalAlignment="Middle">
<font fontName="Calibri" size="13" isBold="false"/>
</textElement>
<text><![CDATA[Clearwater,FL 337564115]]></text>
</staticText>
<staticText>
<reportElement uuid="68f99313-089f-4856-9b3b-1de9b8141c8e" x="224" y="143" width="119" height="16"/>
<textElement verticalAlignment="Middle">
<font fontName="Calibri" size="13" isBold="false"/>
</textElement>
<text><![CDATA[Due Date]]></text>
</staticText>
<staticText>
<reportElement uuid="68f99313-089f-4856-9b3b-1de9b8141c8e" x="311" y="254" width="23" height="16"/>
<textElement verticalAlignment="Middle">
<font fontName="Calibri" size="13" isBold="false"/>
</textElement>
<text><![CDATA[To:]]></text>
</staticText>
<staticText>
<reportElement uuid="68f99313-089f-4856-9b3b-1de9b8141c8e" x="0" y="163" width="119" height="16"/>
<textElement verticalAlignment="Middle">
<font fontName="Calibri" size="13" isBold="false"/>
</textElement>
<text><![CDATA[Name:]]></text>
</staticText>
<staticText>
<reportElement uuid="68f99313-089f-4856-9b3b-1de9b8141c8e" x="381" y="125" width="159" height="16"/>
<textElement verticalAlignment="Middle">
<font fontName="Calibri" size="13" isBold="false"/>
</textElement>
<text><![CDATA[1243 S Martin Luther King Jr]]></text>
</staticText>
<staticText>
<reportElement uuid="68f99313-089f-4856-9b3b-1de9b8141c8e" x="381" y="144" width="159" height="16"/>
<textElement verticalAlignment="Middle">
<font fontName="Calibri" size="13" isBold="false"/>
</textElement>
<text><![CDATA[Ave Unit C201]]></text>
</staticText>
<staticText>
<reportElement uuid="68f99313-089f-4856-9b3b-1de9b8141c8e" x="0" y="125" width="119" height="16"/>
<textElement verticalAlignment="Middle">
<font fontName="Calibri" size="13" isBold="false"/>
</textElement>
<text><![CDATA[Enrollee ID:]]></text>
</staticText>
<image>
<reportElement uuid="a647e2c1-3f18-47ed-8bb6-0940492843e2" x="0" y="0" width="334" height="63"/>
<imageExpression><![CDATA[$P{path}+"aarp_logo.png"]]></imageExpression>
</image>
<textField>
<reportElement uuid="1600e59d-be63-48cf-a53d-34d663928d09" x="108" y="125" width="100" height="16"/>
<textElement/>
<textFieldExpression><![CDATA[$P{policyNbr}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="1600e59d-be63-48cf-a53d-34d663928d09" x="107" y="143" width="100" height="16"/>
<textElement/>
<textFieldExpression><![CDATA[$P{accountId}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="1600e59d-be63-48cf-a53d-34d663928d09" x="107" y="163" width="100" height="16"/>
<textElement/>
<textFieldExpression><![CDATA[$P{firstName}+" "+$P{lastName}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="1600e59d-be63-48cf-a53d-34d663928d09" x="107" y="182" width="100" height="16"/>
<textElement/>
<textFieldExpression><![CDATA[$P{frequency}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="1600e59d-be63-48cf-a53d-34d663928d09" x="301" y="143" width="100" height="16"/>
<textElement/>
<textFieldExpression><![CDATA[$P{effDate}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="1600e59d-be63-48cf-a53d-34d663928d09" x="301" y="125" width="100" height="16"/>
<textElement/>
<textFieldExpression><![CDATA[$P{amount}]]></textFieldExpression>
</textField>
</band>
</title>
<detail>
<band height="98">
<componentElement>
<reportElement uuid="80fd2c41-8337-450e-ac79-99a19fcfdc73" key="table 2" style="table 2" x="1" y="0" width="540" height="98"/>
<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">
<datasetRun subDataset="datasetOne" uuid="e9aa6c17-781e-41e9-8eb8-79526d0bddb0">
<datasetParameter name="amount">
<datasetParameterExpression><![CDATA[$P{amount}]]></datasetParameterExpression>
</datasetParameter>
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("/sendDetail/results")]]></dataSourceExpression>
</datasetRun>
<jr:column uuid="66d5e38d-7d0c-4eb6-85f8-52cfd7f240a0" width="82">
<jr:columnHeader style="table 2_CH" height="30" rowSpan="1">
<staticText>
<reportElement uuid="92cfb518-38e4-484e-9a41-a1e5d53927e9" x="0" y="0" width="82" height="30"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<text><![CDATA[Invoice Number]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table 2_TD" height="20" rowSpan="1">
<textField>
<reportElement uuid="78fb6f48-1cd5-4692-817d-f811dd59a570" x="0" y="0" width="82" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{accountId}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column uuid="ff61e14f-5e24-48f4-841c-e8af679fae6c" width="82">
<jr:columnHeader style="table 2_CH" height="30" rowSpan="1">
<staticText>
<reportElement uuid="1933c38d-4a06-4496-8f18-3feec9655960" x="0" y="0" width="82" height="30"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<text><![CDATA[Effective Date]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table 2_TD" height="20" rowSpan="1">
<textField isBlankWhenNull="true">
<reportElement uuid="f0412d18-6093-483f-86d3-aacbd2d47a6f" x="0" y="0" width="82" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{effDate}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column uuid="4d483cce-1bfe-44ed-9533-123f5c01d955" width="137">
<jr:columnHeader style="table 2_CH" height="30" rowSpan="1">
<staticText>
<reportElement uuid="6a1bfbb1-f538-484b-b7ca-dcdb01685b75" x="0" y="0" width="137" height="30"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<text><![CDATA[Description]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table 2_TD" height="20" rowSpan="1">
<textField isBlankWhenNull="true">
<reportElement uuid="275b32d5-ce4b-4ef6-b7e3-229b103feadf" x="0" y="0" width="137" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{description}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column uuid="3448ad87-41d0-4d8e-b760-c9f68c7c9892" width="160">
<jr:columnHeader style="table 2_CH" height="30" rowSpan="1">
<staticText>
<reportElement uuid="44e5026f-aba1-43a5-b357-621e56fdd239" x="0" y="0" width="160" height="30"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<text><![CDATA[Billing Period]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table 2_TD" height="20" rowSpan="1">
<textField isBlankWhenNull="true">
<reportElement uuid="5b71dcac-1142-43ee-90c8-e4ea4a156c1f" x="0" y="0" width="160" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{period}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column uuid="31c4232c-9a4f-47cd-a54b-8ce5f870f783" width="77">
<jr:columnHeader style="table 2_CH" height="30" rowSpan="1">
<staticText>
<reportElement uuid="a787230a-809e-4681-92c0-622b2c3021a1" x="0" y="0" width="77" height="30"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<text><![CDATA[Current Amount]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table 2_TD" height="20" rowSpan="1">
<textField isBlankWhenNull="true">
<reportElement uuid="08a96cb3-dade-496c-884d-f92fc590104e" x="0" y="0" width="77" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$P{amount}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>
</jasperReport>
XML文件:
<sendDetail>
<results>
<effDate>2015-10-20</effDate>
<period>DEC 1;2015 TO FEB 29;2016</period>
<amount>100.25</amount>
<totalAmount>184.54</totalAmount>
<description>Premium</description>
</results>
<results>
<effDate>2015-10-20</effDate>
<period>DEC 1;2015 TO FEB 29;2016</period>
<amount>132.41</amount>
<totalAmount>0</totalAmount>
<description>Premium Cancellation</description>
</results>
<results>
<effDate>2015-07-20</effDate>
<period>SEP 1;2015 TO NOV 30;2015</period>
<amount>154.21</amount>
<totalAmount>0</totalAmount>
<description>Premium Cancellation</description>
</results>
<results>
<effDate>2015-07-20</effDate>
<period>SEP 1;2015 TO NOV 30;2015</period>
<amount>165.46</amount>
<totalAmount>177.48</totalAmount>
<description>Premium</description>
</results>
</sendDetail>