尝试显示java bean的子列表

时间:2016-08-02 11:55:05

标签: jasper-reports

我在尝试打印出我的Member对象的变量字段m1,m2,m3时遇到类强制转换异常,该对象是我的主java bean Outer.java的子列表javabean

java.lang.ClassCastException: com.mirriad.model.Member cannot be cast to java.lang.String

请问我在哪里错了。我花了很长时间寻找文件来帮助我。

public class Outer {

    private String clientName;
    private List<Member> members;

    public Outer() {}
   //getters and setters omitted
}

public class Member {

    private final String m1;
    private final int m2;
    private final int m3;

    public Member(String m1, int m1, int m1) {
        this.m1 = m1;
        this.m1 = m1;
        this.m1 = m1;
    }
    //getters and setters omitted
}

Jasper 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" language="java"     name="orderFormFinal" pageWidth="612" pageHeight="792" columnWidth="555"      leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<subDataset name="dataset1">
    <field name="m1" class="java.lang.String">
        <fieldDescription><![CDATA[_THIS]]></fieldDescription>
    </field>
</subDataset>
<field name="clientName" class="java.lang.String"/>
<field name="members" class="java.util.Collection"/>
<detail>
    <band height="263" splitType="Stretch">
        <staticText>
            <reportElement x="0" y="4" width="100" height="20"/>
            <text><![CDATA[Order Details]]></text>
        </staticText>
        <staticText>
            <reportElement x="53" y="30" width="100" height="20"/>
            <text><![CDATA[Client Name]]></text>
        </staticText>
        <textField>
            <reportElement x="153" y="30" width="100" height="20"/>
            <textFieldExpression><![CDATA[$F{clientName}]]></textFieldExpression>
        </textField>
        <componentElement>
            <reportElement x="53" y="29" width="400" height="50"/>
            <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">
                <datasetRun subDataset="dataset1">
                    <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{members})]]></dataSourceExpression>
                </datasetRun>
                <jr:listContents height="20" width="400">
                    <textField>
                        <reportElement x="0" y="0" width="100" height="20"/>
                        <box leftPadding="10">
                            <topPen lineWidth="1.0"/>
                            <leftPen lineWidth="1.0"/>
                            <bottomPen lineWidth="1.0"/>
                            <rightPen lineWidth="1.0"/>
                        </box>
                        <textElement/>
                        <textFieldExpression><![CDATA[$F{m1}]]></textFieldExpression>
                    </textField>
                </jr:listContents>
            </jr:list>
        </componentElement>
    </band>
</detail>
</jasperReport>

0 个答案:

没有答案