Jasper iReport:从bean中检索字段值时出错

时间:2015-11-03 10:52:44

标签: java jasper-plugin

我试图在Netbeans中将bean的日期列表传递给jasper插件,但是我收到错误。 我已按照本指南http://javabeansinjasper.blogspot.cz/2011/01/javabeans-as-datasource-in.html#comment-form

错误:

Error filling print... Error retrieving field value from bean : den 
net.sf.jasperreports.engine.JRException: Error retrieving field value from bean : den      
at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(JRAbstractBeanDataSource.java:123)      
at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getFieldValue(JRAbstractBeanDataSource.java:96)      
at net.sf.jasperreports.engine.data.JRBeanCollectionDataSource.getFieldValue(JRBeanCollectionDataSource.java:109)      
at net.sf.jasperreports.engine.fill.JRFillDataset.setOldValues(JRFillDataset.java:1358)      
at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:1259)      
at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:1235)      
at net.sf.jasperreports.engine.fill.JRBaseFiller.next(JRBaseFiller.java:1614)      
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:150)      
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:963)      
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:892)      
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:114)      
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:584)      
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:930)      
at com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:928)      
at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1423)      
at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2033)  
Caused by: java.lang.NoSuchMethodException: Unknown property 'den' on class 'class java.lang.String'      
at org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1322)      
at org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:770)      
at org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:846)      
at org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:426)      
at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(JRAbstractBeanDataSource.java:111)      ... 15 more 

这是一个bean:

public class ListDays {

public ListDays(String den) {
    this.den = den;
}

public ListDays() {
}

public String den;

public String getDen() {
    return den;
}

public void setDen(String den) {
    this.den = den;
}

public static Collection getSeznamDnu(){
    List<String> seznamDnu = new ArrayList<>();
    try {
        for (int i = 0; i<LocalDate.now().getMonth().length(LocalDate.now().isLeapYear()) ;i++){
            LocalDate prvniDenMesice = LocalDate.now().withDayOfMonth(1);
            seznamDnu.add(prvniDenMesice.plusDays(i).format(DateTimeFormatter.ofPattern("EE dd")));}
    } catch (Exception e) {
        System.out.println(e);
    }
    return seznamDnu;

}

}

这是一份报告:

<?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="null" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="0f6a9791-50d4-4aff-9b3f-da0e5f528443">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="den" class="java.lang.String">
        <fieldDescription><![CDATA[den]]></fieldDescription>
    </field>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="79" splitType="Stretch"/>
    </title>
    <pageHeader>
        <band height="35" splitType="Stretch"/>
    </pageHeader>
    <columnHeader>
        <band height="61" splitType="Stretch">
            <staticText>
                <reportElement x="113" y="2" width="100" height="20" uuid="6b5fe0c5-60a2-4db6-96d6-cb9d065e17ff"/>
                <text><![CDATA[den]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="125" splitType="Stretch">
            <textField>
                <reportElement x="113" y="29" width="100" height="20" uuid="f588ecab-7ede-4e2c-80b9-994efcc45dd8"/>
                <textFieldExpression><![CDATA[$F{den}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <columnFooter>
        <band height="45" splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band height="54" splitType="Stretch"/>
    </pageFooter>
    <summary>
        <band height="42" splitType="Stretch"/>
    </summary>
</jasperReport>

提前致谢。已经堆积了很长一段时间了。希望问题是可以理解的。

1 个答案:

答案 0 :(得分:0)

除了一些小的调整 - 创建用于生成变量den的收集和初始化的分离包和类 - 主要问题在于:   do{ try ValidateData.validateEmail(emailTextView.text!) print("Campo Valido") }catch let error{ print(error) }

我用Strings而不是bean来填充集合。代码更改为:

seznamDnu.add(prvniDenMesice.plusDays(i).format(DateTimeFormatter.ofPattern("EE dd")));}

一切正常。现在看一下代码,我还要注意到我并没有真正选择bean的名字。