我对 JasperReports 有点新鲜。我正在尝试使用 iReport 在示例报告的其中一列中打印名称列表。虽然列表正确显示但它没有按照需要提供输出格式。
收到的输出:
Merchant Name Fruits Sold
Marx [Fiji apple, Kashmir apple, Shimla apple]
Stalin [Fiji apple, Kashmir apple, Shimla apple]
预期输出应为:
Merchant Name Fruits Sold
Marx Fiji apple
Kashmir apple
Shimla apple
Stalin Fiji apple
Kashmir apple
Shimla apple
我在报告中为“售完水果”栏使用了一个List元素。在列表框架中,我将来自Javabean的文本字段元素$ {fruitsForSale}。 List元素的连接表达式为$ P {REPORT_CONNECTION},以使用与主数据集相同的连接。
Javabean类如下:
import java.util.ArrayList;
import java.util.List;
public class FruitSeller {
private String merchantName;
private List<String> fruitsForSale;
public String getMerchantName() {
return this.merchantName;
}
public void setMerchantName(String merchantName) {
this.merchantName = merchantName;
}
public List<String> getFruitsForSale() {
return this.fruitsForSale;
}
public void setFruitsForSale(List<String> fruitsForSale) {
this.fruitsForSale = fruitsForSale;
}
public static List<FruitSeller> prepareReport() {
List fruitSellerList = new ArrayList();
FruitSeller fruitSeller = new FruitSeller();
fruitSeller.setMerchantName("Marx");
List fruitsForSale = new ArrayList();
fruitsForSale.add("Fiji apple");
fruitsForSale.add("Kashmir apple");
fruitsForSale.add("Shimla apple");
fruitSeller.setFruitsForSale(fruitsForSale);
fruitSellerList.add(fruitSeller);
FruitSeller fruitSeller2 = new FruitSeller();
List fruitsForSale2 = new ArrayList();
fruitSeller2.setMerchantName("Stalin");
fruitsForSale2.add("Fiji apple");
fruitsForSale2.add("Kashmir apple");
fruitsForSale2.add("Shimla apple");
fruitSeller2.setFruitsForSale(fruitsForSale2);
fruitSellerList.add(fruitSeller2);
return fruitSellerList;
}
}
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="TaskReport" language="groovy" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="fe637f77-a273-4977-a964-127a514b9844">
<subDataset name="dataset1" uuid="d4eb79c1-9e33-42d2-ae15-a8416f7c1cb4"/>
<subDataset name="New Dataset 1" uuid="18df23e8-0545-4bef-aef8-804e425d990f"/>
<subDataset name="dataset6" uuid="09a35364-9d98-4c70-9246-de2759b0d421"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="fruitsForSale" class="java.util.List">
<fieldDescription><![CDATA[fruitsForSale]]></fieldDescription>
</field>
<field name="merchantName" class="java.lang.String">
<fieldDescription><![CDATA[merchantName]]></fieldDescription>
</field>
<columnHeader>
<band height="34" splitType="Stretch">
<staticText>
<reportElement uuid="8dbb8a02-6cb2-404a-af92-34c129fdae11" stretchType="RelativeToBandHeight" x="0" y="0" width="262" height="34"/>
<box>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement verticalAlignment="Middle">
<font size="12" isBold="true"/>
</textElement>
<text><![CDATA[Merchant Name]]></text>
</staticText>
<staticText>
<reportElement uuid="389f9247-f6d9-43b7-86e7-ad6aed456117" x="262" y="0" width="293" height="34"/>
<box>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement verticalAlignment="Middle">
<font size="12" isBold="true"/>
</textElement>
<text><![CDATA[Fruits Sold]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="44" splitType="Stretch">
<textField>
<reportElement uuid="94bef980-1315-418a-96f8-4a5f6bf21e9a" x="0" y="0" width="262" height="44"/>
<box>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement>
<font size="9"/>
</textElement>
<textFieldExpression><![CDATA[$F{merchantName}]]></textFieldExpression>
</textField>
<componentElement>
<reportElement uuid="e3c1916e-8785-4517-9f99-132edd759cc7" x="262" y="1" width="293" height="43"/>
<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="dataset6" uuid="8bcd4e11-7efd-48bf-9314-fd84812879d7">
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
<jr:listContents height="43" width="293"/>
</jr:list>
</componentElement>
<textField>
<reportElement uuid="1fe0b910-b7f8-48e9-aa21-5b0073d8b6f5" x="262" y="0" width="293" height="44"/>
<box>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{fruitsForSale}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
任何人都可以建议我可能出错的地方吗?