2

我正在使用iReportJasperReports,当我开始做报告时,默认情况下iReport使用Groovy,但我需要更改为 Java(我的工作受到限制),我使用Groovy制作报告并且它工作得很好但是当我更改为Java语言,我遇到了麻烦,因为我在报告中使用了一个类(来自类的 java 的字段),所以错误是:myfield cannot be resolved or is not a field.

我用来做报告的课程是:

public final class GrupoEstadistico implements Serializable {

    private Estadistico ccDocumento;
    private Estadistico ccNombres;

    //another class that is an attribute of type Estadistico

    private Date periodo;
    private String tipoEntidad;

    //and another primitives atributes: strings, int

    //getters and setters
}

这是Estadistico类:

public final class Estadistico implements Serializable, Comparable<Estadistico> {

    private String nombreEntidad;
    private int codigo;
    private int numeroConsultas = 0;

    //and aother primitives atributes: strings, int
    //getters and setters
}

我在报告中使用了GrupoEstadistico类的所有属性,就像一个字段一样。

我使用表达式来获取每个Estadistico的值,例如:

$F{ccDocumento}.numeroConsultasanyone 

当我尝试编译报告时遇到的麻烦是:

numeroConsultas cannot be resolved  or is not a field.

我理解正在发生的是:

  • iReport找不到我的类属性,因此这有
  • iRreport不明白我使用的表达方式。

这是我试图解决我的问题:

  1. 添加一个 jar 文件,其中包含iReport的类路径所需的类。
  2. 添加导入,例如:reporte.model.GruoEstadistico在我的报告的属性中。

  3. 我已经编辑了xml并添加了标签 scriptlet:

 <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="ListaConsultaEstadistico" pageWidth="895" pageHeight="595" 
 orientation="Landscape" columnWidth="855" leftMargin="20" rightMargin="20" 
 topMargin="20" bottomMargin="20" 
 scriptletClass="reporte.model.GrupoEstadistico" 
 uuid="b0990d7b-fade-4200-a2ef-fb0416f5a9c2">

更新:

我通过以下方式从Java代码调用我的报告:

/**Create a List of GrupoEstadistico class. */

List<GrupoEstadistico> this.dataSource = new ArrayList<GrupoEstadistico>();

/**Fill my List....*/


JasperPrint jasperPrint= JasperFillManager.fillReport( reportPath,this.parametros,
                 new JRBeanCollectionDataSource( this.dataSource ));  

数据源是一个 List<GrupoEstadistico>

但仍然无法正常工作。

谁能帮我?

4

1 回答 1

1

使用 java 程序在 ireport 中发送您的对象。使用您的实例和属性的名称定义一个字段。例如,假设您使用grupoEstadistico 发送您的类实例,在ireport 中定义一个名称为“grupoEstadistico.tipoEntidad”的字段。并拖动任何带区中的文本字段。 右键单击-> 编辑表达式-> 删除 ${field}-> 双击您的字段-> 单击应用 它将在 * iReport *中添加您的属性。现在,如果您将文件下载为 pdf 格式,它将显示您在这种情况下发送的数据。

于 2013-10-02T11:07:53.417 回答