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:
- add a jar file with the classes required to classpath of iReport.
add the import like:
reporte.model.GruoEstadistico
in the properties of my report.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?
The method getNumeroConsultas() is undefined for the type Object
– Cristian