【问题标题】:JasperReports JRBeanCollectionDataSource in a list from JavaBeansJasperReports JRBeanCollectionDataSource 在来自 JavaBeans 的列表中
【发布时间】:2015-09-11 17:04:10
【问题描述】:

我是 JasperReports 的新手。我做了一些简单的报告,但没有这么复杂。我在论坛上搜索了一天以上,但我无法让它工作。

我得到的错误:

从 bean 检索字段值时出错:eventPlanTimeSlotBeanDataSet

如果有人能帮我把它变成摇滚,我将非常感激。

提前致谢, 汤姆

我的豆子:

public class EventPlanTimeSlotBean {

private String timeSlot;

private List<OrganizerResultReportBean> orgResultBeans = new ArrayList<OrganizerResultReportBean>();

public EventPlanTimeSlotBean(String timeSlot, List<OrganizerResultReportBean> orgResultBeans) {
    this.timeSlot = timeSlot;
    this.orgResultBeans = orgResultBeans;
}

public String getTimeSlot() {
    return timeSlot;
}

public void setTimeSlot(String timeSlot) {
    this.timeSlot = timeSlot;
}

public List<OrganizerResultReportBean> getOrgResultBeans() {
    return orgResultBeans;
}

public void setOrgResultBeans(List<OrganizerResultReportBean> orgResultBeans) {
    this.orgResultBeans = orgResultBeans;
}

我的 jrxml 文件:

<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="120"/>
<subDataset name="dataset1">
     <field name="timeSlot" class="java.lang.String">
        <fieldDescription><![CDATA[_THIS]]></fieldDescription>
    </field>
</subDataset>
<parameter name="eventPlanNameParam" class="java.lang.String"/>
<parameter name="destinationNameColumnLabel" class="java.lang.String"/>
<parameter name="destinationCityColumnLabel" class="java.lang.String"/>
<parameter name="totalFlightCostsColumnLabel" class="java.lang.String"/>
<parameter name="timeSlotColumnLabel" class="java.lang.String"/>

<field name="eventPlanTimeSlotBeanDataSet" class="java.util.List"/>

<title>
    <band height="110" splitType="Stretch">
        <staticText>
            <reportElement mode="Transparent" x="0" y="20" width="50" height="20" uuid="2af07c91-7b37-4c3a-8eea-53bfc065426e"/>
            <text><![CDATA[Name:]]></text>
        </staticText>
        <textField isBlankWhenNull="true">
            <reportElement mode="Transparent" x="60" y="20" width="300" height="20" uuid="2710e1b0-2493-409e-903b-381ddbb08392"/>
            <textFieldExpression><![CDATA[$P{eventPlanNameParam}]]></textFieldExpression>
        </textField>
    </band>
</title>
<columnHeader>
    <band height="30" splitType="Stretch">
        <textField>
            <reportElement mode="Transparent" x="0" y="5" width="100" height="20" uuid="d7a2f1cf-5325-4841-b46b-01c3c131d3ea"/>
            <textFieldExpression><![CDATA[$P{timeSlotColumnLabel}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement mode="Transparent" x="100" y="5" width="100" height="20" uuid="d7a2f1cf-5325-4841-b46b-01c3c131d3ea"/>
            <textFieldExpression><![CDATA[$P{destinationNameColumnLabel}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement mode="Transparent" x="200" y="5" width="100" height="20" uuid="cccc198b-10db-434d-b5c1-ddfcf0b3a0ab"/>
            <textFieldExpression><![CDATA[$P{destinationCityColumnLabel}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement mode="Transparent" x="300" y="5" width="100" height="20" uuid="cccc198b-10db-434d-b5c1-ddfcf0b3a0ab"/>
            <textFieldExpression><![CDATA[$P{totalFlightCostsColumnLabel}]]></textFieldExpression>
        </textField>
        <line>
            <reportElement mode="Opaque" x="0" y="24" width="511" height="1" uuid="ca213328-f473-4c93-a888-c1fd2181f0e4"/>
        </line>
    </band>
</columnHeader>
<detail>
    <band height="25" splitType="Stretch">
        <componentElement>
            <reportElement x="100" y="0" width="400" height="20" uuid="320e66be-b719-4e1d-b1c8-9215179d7200"/>
            <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="dataset1" uuid="056d45ca-4628-4bc5-bb1f-f44bb6d74c82">
                    <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{eventPlanTimeSlotBeanDataSet})]]></dataSourceExpression>
                </datasetRun>
                <jr:listContents height="20" width="400">
                    <textField>
                        <reportElement x="0" y="0" width="100" height="20" uuid="db39f665-58b9-43ba-89dc-0d93e2f02a77"/>
                        <box leftPadding="10">
                            <topPen lineWidth="1.0"/>
                            <leftPen lineWidth="1.0"/>
                            <bottomPen lineWidth="1.0"/>
                            <rightPen lineWidth="1.0"/>
                        </box>
                        <textFieldExpression><![CDATA[$F{timeSlot}]]></textFieldExpression>
                    </textField>
                </jr:listContents>
            </jr:list>
        </componentElement>
    </band>
</detail>

填写报告:

try {
        jasperPrint = JasperFillManager.fillReport(jreport, meetingResultMap,
                new JRBeanCollectionDataSource(getDataSource(session, searchTask, eventPlan)));
    } catch (JRException e) {
        throw new LocalizedException("meeting_report_pdf_could_not_be_created" + ": " + e.getMessage());
    }

【问题讨论】:

    标签: java jasper-reports


    【解决方案1】:

    终于搞定了!

    这是我的工作代码:

    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="120"/>
    <subDataset name="dataset1" uuid="6de4170d-97fa-4f08-bd45-f04be2f65e9f">
        <field name="destinationName" class="java.lang.String"/>
    </subDataset>
    <parameter name="destinationNameColumnLabel" class="java.lang.String"/>
    <parameter name="destinationCityColumnLabel" class="java.lang.String"/>
    <parameter name="totalFlightCostsColumnLabel" class="java.lang.String"/>
    <parameter name="timeSlotColumnLabel" class="java.lang.String"/>
    <parameter name="eventPlanNameParam" class="java.lang.String"/>
    <field name="orgResultBeans" class="java.util.List"/>
    <field name="timeSlot" class="java.lang.String"/>
    <title>
        <band height="110" splitType="Stretch">
            <staticText>
                <reportElement mode="Transparent" x="0" y="20" width="50" height="20" uuid="2af07c91-7b37-4c3a-8eea-53bfc065426e"/>
                <text><![CDATA[Name:]]></text>
            </staticText>
            <textField isBlankWhenNull="true">
                <reportElement mode="Transparent" x="60" y="20" width="300" height="20" uuid="2710e1b0-2493-409e-903b-381ddbb08392"/>
                <textFieldExpression><![CDATA[$P{eventPlanNameParam}]]></textFieldExpression>
            </textField>
        </band>
    </title>
    <columnHeader>
        <band height="30" splitType="Stretch">
            <textField>
                <reportElement mode="Transparent" x="0" y="5" width="100" height="20" uuid="d7a2f1cf-5325-4841-b46b-01c3c131d3ea"/>
                <textFieldExpression><![CDATA[$P{timeSlotColumnLabel}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement mode="Transparent" x="100" y="5" width="100" height="20" uuid="d7a2f1cf-5325-4841-b46b-01c3c131d3ea"/>
                <textFieldExpression><![CDATA[$P{destinationNameColumnLabel}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement mode="Transparent" x="200" y="5" width="100" height="20" uuid="cccc198b-10db-434d-b5c1-ddfcf0b3a0ab"/>
                <textFieldExpression><![CDATA[$P{destinationCityColumnLabel}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement mode="Transparent" x="300" y="5" width="100" height="20" uuid="cccc198b-10db-434d-b5c1-ddfcf0b3a0ab"/>
                <textFieldExpression><![CDATA[$P{totalFlightCostsColumnLabel}]]></textFieldExpression>
            </textField>
            <line>
                <reportElement mode="Opaque" x="0" y="24" width="511" height="1" uuid="ca213328-f473-4c93-a888-c1fd2181f0e4"/>
            </line>
        </band>
    </columnHeader>
    <detail>
        <band height="25" splitType="Stretch">
            <componentElement>
                <reportElement x="100" y="0" width="400" height="20" uuid="320e66be-b719-4e1d-b1c8-9215179d7200"/>
                <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="dataset1" uuid="056d45ca-4628-4bc5-bb1f-f44bb6d74c82">
                        <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{orgResultBeans})]]></dataSourceExpression>
                    </datasetRun>
                    <jr:listContents height="20" width="400">
                        <textField>
                            <reportElement x="0" y="0" width="100" height="20" uuid="db39f665-58b9-43ba-89dc-0d93e2f02a77"/>
                            <box leftPadding="10">
                                <topPen lineWidth="1.0"/>
                                <leftPen lineWidth="1.0"/>
                                <bottomPen lineWidth="1.0"/>
                                <rightPen lineWidth="1.0"/>
                            </box>
                            <textFieldExpression><![CDATA[$F{destinationName}]]></textFieldExpression>
                        </textField>
                    </jr:listContents>
                </jr:list>
            </componentElement>
        </band>
    </detail>
    <columnFooter>
        <band height="45" splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band height="54" splitType="Stretch"/>
    </pageFooter>
    <summary>
        <band height="42" splitType="Stretch"/>
    </summary>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-25
      相关资源
      最近更新 更多