2
votes

I'm working with iReport and JasperReports, when I began to do my report, iReport by default use Groovy, but I need to change to Java (constrains in my job), I make my report with Groovy and It's works perfectly but when I change to Java language, I get a trouble, because I use a class(fields from java of a class) in my report, so the Mistake is: myfield cannot be resolved or is not a field.

The class that I use to do my report is:

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
}

This is the Estadistico class:

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
}

And I use all attributes of the class GrupoEstadistico in my report like a fields.

And I use expressions to get the values of each Estadistico like:

$F{ccDocumento}.numeroConsultasanyone 

The trouble that I get when I try to compile the report is:

numeroConsultas cannot be resolved  or is not a field.

What I understand is happening is:

  • iReport not find my class attributes thus this has
  • iRreport not understand the expressions I use.

This is that I been tried to solve my problem:

  1. add a jar file with the classes required to classpath of iReport.
  2. add the import like: reporte.model.GruoEstadistico in the properties of my report.

  3. And I been edited the xml and I add the tag 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">

UPDATE:

I'm calling my report from the Java code the following way:

/**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 ));  

The dataSource is a List<GrupoEstadistico>

But still does not work.

Can anyone help me?

1
Try call public getter $F{ccDocumento}.getNumeroConsultas()Nicolai
@Nicolai, thanks but not works, when I try to call the getter I get: The method getNumeroConsultas() is undefined for the type ObjectCristian
How do you send ccDocumento in template?Nicolai
Which class have field $F{ccDocumento} in jrxml? Is it java.lang.Object? "The method getNumeroConsultas() is undefined for the type Object"sanBez
And scriptlet is not need for you. Define only fields ccDocumento, ccNombres, etc... in jrxml. And check getters for this members of classsanBez

1 Answers

1
votes

Send your object in ireport using java program. Define a field with name of your instance and attribute. e.g. Suppose you send your class instance with grupoEstadistico, define a field in ireport with name "grupoEstadistico.tipoEntidad". and Drag a textfield in any band. RightClick->Edit Expression-> remove ${field}-> double click on your field->click apply It will add you attribute in *iReport *. now if you download your file as pdf format , it will show data what ever you send in this instance.