gpt4 book ai didi

java - JasperReports JavaBeans 列表中的 JRBeanCollectionDataSource

转载 作者:太空宇宙 更新时间:2023-11-04 13:27:16 25 4
gpt4 key购买 nike

我是 JasperReports 的新手。我做过一些简单的报告,但没有这么复杂。我在论坛上搜索了不止一天,但我就是无法让它发挥作用。

我收到的错误:

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

如果有人能帮助我实现这一点,我将非常感激。

提前致谢,汤姆

我的 bean :

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());
}

最佳答案

终于成功了!

这是我的工作代码:

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

关于java - JasperReports JavaBeans 列表中的 JRBeanCollectionDataSource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32518029/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com