antoniocv Posted December 17, 2008 Share Posted December 17, 2008 Hi:I am using Dynamique Jasper (DJ) to generata dynamique reports thought I think my problem is with JasperReports (JR) since the DJ interface seems to call directly the JR methods.My code is below and I am trying to use a bean with String, Date and Long objects as the data for the report. I pass the data bean list to the JRBeanCollectionDataSource and this data source is passed to the DJ method to generate the JasperPrint.After the generateJasperPrint() invoke, this exception is thrown:net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression : Source text : $F{fec} at ip2.comun.informes.negocio.ControladorInformesDinamicos.rellenarInforme(ControladorInformesDinamicos.java:913) at ip2.comun.informes.negocio.ControladorInformesDinamicos.construirYRellenarInforme(ControladorInformesDinamicos.java:458) at ip2.comun.informes.negocio.ControladorInformesDinamicos.generarInformeAStream(ControladorInformesDinamicos.java:305) at ip2.comun.informes.negocio.ControladorInformesDinamicos.generarInformeAStream(ControladorInformesDinamicos.java:295) at ip2.gremlins.fracc.control.JasperAccion.ejecutar(JasperAccion.java:286) at ip2.comun.controlapp.control.ServletAccion.ejecutarAccion(ServletAccion.java:344) at ip2.comun.controlapp.control.ServletAccion.procesarAccion(ServletAccion.java:157) at ip2.comun.controlapp.control.ServletAccion.doGet(ServletAccion.java:104) at javax.servlet.http.HttpServlet.service(HttpServlet.java:743) at javax.servlet.http.HttpServlet.service(HttpServlet.java:856) at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65) at ip2.comun.controlapp.control.TicketFilter.doFilter(TicketFilter.java:64) at com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:15) at ip2.comun.controlapp.control.TrazaEjecucionAccionesFilter.doFilter(TrazaEjecucionAccionesFilter.java:65) at com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:17) at ip2.comun.controlapp.control.FRACCInitialFilter.doFilter(FRACCInitialFilter.java:101) at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:621) at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:370) at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:871) at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:453) at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:221) at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:122) at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:111) at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260) at oracle.oc4j.network.ServerSocketAcceptHandler.procClientSocket(ServerSocketAcceptHandler.java:239) at oracle.oc4j.network.ServerSocketAcceptHandler.access$700(ServerSocketAcceptHandler.java:34) at oracle.oc4j.network.ServerSocketAcceptHandler$AcceptHandlerHorse.run(ServerSocketAcceptHandler.java:880) at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303) at java.lang.Thread.run(Thread.java:595)Caused by: net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression : Source text : $F{fec} at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:197) at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:537) at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:505) at net.sf.jasperreports.engine.fill.JRFillElement.evaluateExpression(JRFillElement.java:813) at net.sf.jasperreports.engine.fill.JRFillTextField.evaluateText(JRFillTextField.java:365) at net.sf.jasperreports.engine.fill.JRFillTextField.evaluate(JRFillTextField.java:352) at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:275) at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:426) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:1380) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:692) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:255) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:113) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:895) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:817) at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:89) at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:601) at ar.com.fdvs.dj.core.DynamicJasperHelper.generateJasperPrint(DynamicJasperHelper.java:245) at ip2.comun.informes.negocio.ControladorInformesDinamicos.rellenarInforme(ControladorInformesDinamicos.java:906) ... 28 moreCaused by: java.lang.ClassCastException: java.util.Date at DynamicReport_1229502094344_346466.evaluate(DynamicReport_1229502094344_346466:239) at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:186) ... 45 moreIf I remove the Date and Long object, it runs ok, but with these types the above exception occurs. I have tried also with JRMapCollectionDataSource but the same problem occurs with these object types.Does anybody knows some issues with these objetc types I need to take in account? Can anybody hel me?I am using JR 2.0.5 an DJ 3.0Thanks a lot in advance,Antonio. Code:ArrayList listaBeans = new ArrayList();listaBeans.add(new BeanDatos("Antonio", "Crespo", "Velasco", "03855305", new Date(), Long.getLong("1000")));listaBeans.add(new BeanDatos("Antonio", "Crespo", "Velasco", "03855305", new Date(), Long.getLong("2000")));listaBeans.add(new BeanDatos("Antonio", "Crespo", "Velasco", "03855305", new Date(), Long.getLong("3000")));listaBeans.add(new BeanDatos("Antonio", "Crespo", "Velasco", "03855305", new Date(), Long.getLong("4000")));listaBeans.add(new BeanDatos("Antonio", "Crespo", "Velasco", "03855305", new Date(), Long.getLong("5000"))); jasperPrint = DynamicJasperHelper.generateJasperPrint(dynamicReport, new ClassicLayoutManager(), new JRBeanCollectionDataSource(listaBeans), new HashMap()); Link to comment Share on other sites More sharing options...
antoniocv Posted December 17, 2008 Author Share Posted December 17, 2008 I have been doing more tests in order to discover the problem and I have more information.If I remove the Date objet of the bean, it seems to run but the Long object is not printed in the report (see file attached). Link to comment Share on other sites More sharing options...
lucianc Posted December 17, 2008 Share Posted December 17, 2008 antoniocvWrote: I am using Dynamique Jasper (DJ) to generata dynamique reports thought I think my problem is with JasperReports (JR) since the DJ interface seems to call directly the JR methods. That doesn't sound like a valid argument to me. I can directly call java.lang.Integer.parseInt("foo") and it doesn't mean that the resulting exception is caused by a problem in the JDK.I think you should post this question on the DynamicJasper forums. On this forum there might not be many people that know how DynamicJasper works, so you might not get the help you need unless you can reproduce the same problem directly with JR.Regards,LucianPost Edited by Lucian Chiriţă at 12/17/08 10:10 Link to comment Share on other sites More sharing options...
antoniocv Posted December 17, 2008 Author Share Posted December 17, 2008 Hello lucianc:Thanks for your reply and help and sorry for posting here instead of Dynamique Jasper forum.You are rigth, I should post my problem in Dynamique Jasper forum but I thought it could be a Jasper problem. I have replicated my test with Jasper only code and I don't have the ClassCastException with the java.util.Date objet, but the report print all no-String atributes with null values.Maybe if I solve this problem with Jasper I could solve in Dynamique and we will not post any other things but jasper in this forumFind attached my jrxml and my pdf.Thanks a lot,AntonioCode:package main;import ip2.gremlins.fracc.accesobd.BeanDatosParaJasperReports;import java.util.ArrayList;import java.util.Collection;import java.util.HashMap;import java.util.Map;import net.sf.jasperreports.engine.JasperCompileManager;import net.sf.jasperreports.engine.JasperExportManager;import net.sf.jasperreports.engine.JasperFillManager;import net.sf.jasperreports.engine.JasperPrint;import net.sf.jasperreports.engine.JasperReport;import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;public class Pruebas { public Pruebas() { } public static void main(String[] args) { Pruebas pruebas = new Pruebas(); String reportName = "plantilla"; JRBeanCollectionDataSource dataSource; JasperReport jasperReport; JasperPrint jasperPrint; Map pars = new HashMap(); pars.put("P_TITULO", "Informe prueba"); pars.put("P_SUBTITULO", "Usando Date"); try{ Collection lista = populateData(); dataSource = new JRBeanCollectionDataSource(lista); jasperReport = JasperCompileManager.compileReport("./src/main/" + reportName + ".jrxml"); jasperPrint = JasperFillManager.fillReport(jasperReport, pars, dataSource); JasperExportManager.exportReportToPdfFile(jasperPrint, "./src/main/" + reportName + ".pdf"); System.out.println("Done!"); } catch (Exception e){ System.out.println(e); e.printStackTrace(); } } private static Collection populateData(){ Collection listaBeans = new ArrayList(); listaBeans.add(new BeanDatosParaJasperReports("Antonio", "Crespo", "Velasco", "03855305", Long.getLong("1000"))); listaBeans.add(new BeanDatosParaJasperReports("Antonio", "Crespo", "Velasco", "03855305", Long.getLong("2000"))); listaBeans.add(new BeanDatosParaJasperReports("Antonio", "Crespo", "Velasco", "03855305", Long.getLong("3000"))); listaBeans.add(new BeanDatosParaJasperReports("Antonio", "Crespo", "Velasco", "03855305", Long.getLong("4000"))); listaBeans.add(new BeanDatosParaJasperReports("Antonio", "Crespo", "Velasco", "03855305", Long.getLong("5000"))); return listaBeans; } }}package ip2.gremlins.fracc.accesobd;import java.util.Date;public class BeanDatosParaJasperReports { private String nombre; private String primerApellido; private String segundoApellido; private String dni; private Date fechaNacimiento; private Long ingresos; public BeanDatosParaJasperReports(String nombre, String primerApellido, String segundoApellido, String dni, Long ingresos, Date fechaNacimiento) { this.setNombre(nombre); this.setPrimerApellido(primerApellido); this.setSegundoApellido(segundoApellido); this.setDni(dni); this.setFechaNacimiento(fechaNacimiento); this.setIngresos(ingresos); } public BeanDatosParaJasperReports(String nombre, String primerApellido, String segundoApellido, String dni, Long ingresos) { this.setNombre(nombre); this.setPrimerApellido(primerApellido); this.setSegundoApellido(segundoApellido); this.setDni(dni); this.setIngresos(ingresos); } public void setNombre(String nombre) { this.nombre = nombre; } public String getNombre() { return nombre; } public void setPrimerApellido(String primerApellido) { this.primerApellido = primerApellido; } public String getPrimerApellido() { return primerApellido; } public void setSegundoApellido(String segundoApellido) { this.segundoApellido = segundoApellido; } public String getSegundoApellido() { return segundoApellido; } public void setDni(String dni) { this.dni = dni; } public String getDni() { return dni; } public void setFechaNacimiento(Date fechaNacimiento) { this.fechaNacimiento = fechaNacimiento; } public Date getFechaNacimiento() { return fechaNacimiento; } public void setIngresos(Long ingresos) { this.ingresos = ingresos; } public Long getIngresos() { return ingresos; }} Link to comment Share on other sites More sharing options...
antoniocv Posted December 17, 2008 Author Share Posted December 17, 2008 In my previous post there was an error and I was not passing any date.I have change the code and the Date is printed in the report but not the Long.Find included the new codeAny ideas?Thanks againAntonio.Code:package main;import ip2.gremlins.fracc.accesobd.BeanDatosParaJasperReports;import java.util.ArrayList;import java.util.Collection;import java.util.HashMap;import java.util.Map;import net.sf.jasperreports.engine.JasperCompileManager;import net.sf.jasperreports.engine.JasperExportManager;import net.sf.jasperreports.engine.JasperFillManager;import net.sf.jasperreports.engine.JasperPrint;import net.sf.jasperreports.engine.JasperReport;import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;public class Pruebas { public Pruebas() { } public static void main(String[] args) { Pruebas pruebas = new Pruebas(); String reportName = "plantilla"; JRBeanCollectionDataSource dataSource; JasperReport jasperReport; JasperPrint jasperPrint; Map pars = new HashMap(); pars.put("P_TITULO", "Informe prueba"); pars.put("P_SUBTITULO", "Usando Date"); try{ Collection lista = populateData(); dataSource = new JRBeanCollectionDataSource(lista); jasperReport = JasperCompileManager.compileReport("./src/main/" + reportName + ".jrxml"); jasperPrint = JasperFillManager.fillReport(jasperReport, pars, dataSource); JasperExportManager.exportReportToPdfFile(jasperPrint, "./src/main/" + reportName + ".pdf"); System.out.println("Done!"); } catch (Exception e){ System.out.println(e); e.printStackTrace(); } } private static Collection populateData(){ Collection listaBeans = new ArrayList(); listaBeans.add(new BeanDatosParaJasperReports("Antonio", "Crespo", "Velasco", "03855305", Long.getLong("1000"), new Date())); listaBeans.add(new BeanDatosParaJasperReports("Antonio", "Crespo", "Velasco", "03855305", Long.getLong("2000"), new Date())); listaBeans.add(new BeanDatosParaJasperReports("Antonio", "Crespo", "Velasco", "03855305", Long.getLong("3000"), new Date())); listaBeans.add(new BeanDatosParaJasperReports("Antonio", "Crespo", "Velasco", "03855305", Long.getLong("4000"), new Date())); listaBeans.add(new BeanDatosParaJasperReports("Antonio", "Crespo", "Velasco", "03855305", Long.getLong("5000"), new Date())); return listaBeans; } }}package ip2.gremlins.fracc.accesobd;import java.util.Date;public class BeanDatosParaJasperReports { private String nombre; private String primerApellido; private String segundoApellido; private String dni; private Date fechaNacimiento; private Long ingresos; public BeanDatosParaJasperReports(String nombre, String primerApellido, String segundoApellido, String dni, Long ingresos, Date fechaNacimiento) { this.setNombre(nombre); this.setPrimerApellido(primerApellido); this.setSegundoApellido(segundoApellido); this.setDni(dni); this.setFechaNacimiento(fechaNacimiento); this.setIngresos(ingresos); } public BeanDatosParaJasperReports(String nombre, String primerApellido, String segundoApellido, String dni, Long ingresos) { this.setNombre(nombre); this.setPrimerApellido(primerApellido); this.setSegundoApellido(segundoApellido); this.setDni(dni); this.setIngresos(ingresos); } public void setNombre(String nombre) { this.nombre = nombre; } public String getNombre() { return nombre; } public void setPrimerApellido(String primerApellido) { this.primerApellido = primerApellido; } public String getPrimerApellido() { return primerApellido; } public void setSegundoApellido(String segundoApellido) { this.segundoApellido = segundoApellido; } public String getSegundoApellido() { return segundoApellido; } public void setDni(String dni) { this.dni = dni; } public String getDni() { return dni; } public void setFechaNacimiento(Date fechaNacimiento) { this.fechaNacimiento = fechaNacimiento; } public Date getFechaNacimiento() { return fechaNacimiento; } public void setIngresos(Long ingresos) { this.ingresos = ingresos; } public Long getIngresos() { return ingresos; }} Link to comment Share on other sites More sharing options...
lucianc Posted December 17, 2008 Share Posted December 17, 2008 Long.getLong("300") returns null (unless you have system property named "300"), see the Javadoc. You probably want Long.valueOf("300").HTH,Lucian Link to comment Share on other sites More sharing options...
antoniocv Posted December 17, 2008 Author Share Posted December 17, 2008 Upsss.Problem solved.Thanks again for your time. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now