Jasper Reports - Error picking bean value

Asked

Viewed 2,311 times

2

I’ve been looking for three days now and I can’t solve this problem. Let’s get the explanation: I’m creating a report in Jaspersoft studio and linking with my database, in the preview of my report (inside Jaspersoft software) everything is working perfectly. As can be seen in the following images: Meu relatório jrxml

Como ele fica no preview

I have only 3 Fields in my report: name, measure and neighborhood.

Inside my software, when I call the report it’s two different mistakes, I can’t figure out what to do.

Follow my sources for better viewing:

Reporterioutils - Class that will generate the report

public static void executarRelatorio(String caminhoRelatorio, Map<String, Object> parametros, String nomeRelatorio, JRBeanCollectionDataSource fonteDados) throws IOException {
    FacesContext context = FacesContext.getCurrentInstance();
    HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();

    //pegar caminho do relatorio jasper
    InputStream reportStream = context.getExternalContext().getResourceAsStream(caminhoRelatorio);
    response.setContentType("application/pdf");

    try {
        ServletOutputStream servletOutput = null;
        try {
            servletOutput = response.getOutputStream();
        } catch (IOException e) {
            e.printStackTrace();
        }

        if (parametros == null) {
            parametros = new HashMap<String, Object>();
        }

        JasperRunManager.runReportToPdfStream(reportStream, servletOutput, parametros, fonteDados);

        try {
            servletOutput.flush();
            servletOutput.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } catch (JRException e) {
        e.printStackTrace();
    } finally {
        context.getResponseComplete();
    }
}

My Managed Bean

public void emitir() {
    relatorios = dao.listarTodos();
    JRBeanCollectionDataSource fonteDados = new JRBeanCollectionDataSource(relatorios); // aqui está vindo completo meu JRbeanCollection está trazendo todos os dados que preciso
    FacesContext context = FacesContext.getCurrentInstance();
    ServletContext servletContext = (ServletContext) context.getExternalContext().getContext();


    try {
        RelatorioUtil.executarRelatorio("/relatorios/RelatorioMedidaCautelar.jasper", null, "Relatorio", fonteDados);
    } catch (IOException ex) {
        Logger.getLogger(MBRelatorio.class.getName()).log(Level.SEVERE, null, ex);
    }

}

This is the mistake it generates

net.sf.jasperreports.engine.JRException: Error retrieving field value from bean : 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:668) at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:649) at net.sf.jasperreports.engine.JasperRunManager.runToPdfStream(JasperRunManager.java:437) at net.sf.jasperreports.engine.JasperRunManager.runReportToPdfStream(JasperRunManager.java:858) at br.com.agilles.medidas.utils.RelatorioUtil.executarRelatorio(RelatorioUtil.java:57) at br.com.agilles.medidas.beans.MBRelatorio.emitir(MBRelatorio.java:58) Caused by: java.lang.NoSuchMethodException: Unknown property '' on class 'class br.com.agilles.medidas.models.Relatorio' at org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1277) at org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:808) at org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:884) at org.apache.commons.beanutils.PropertyUtils.getProperty(Propertyutils.java:464) at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(Jrabstractbeandatasource.java:111) ... 57 more

Important to say: My Jrbeancollectiondatasource is coming completely filled with all the right data: name, measure and neighborhood.

Someone can help me?

  • java.lang.NoSuchMethodException: Unknown property '' on class 'class br.com.agilles.medidas.models.Relatorio'&#It seems that here, he is trying to find a variable with empty field declaration, and finds no variable declared as "". I’ve never worked much with JR, but try to see if your Data source contains the Fields you need popular, with the correct names.

  • Yes, it seems that he tries to access by reflection within the Report class an unnamed field.

  • my data source is coming with the same fields as the report. It comes with an array of size 3 that is coming from the database. Each object is populated with the field name, measure and neighborhood.

  • I get it, @Jilles. Please check if there is no wrong value inside the file .jrxml, and also, if possible, edit the question and put the class Relatorio.

1 answer

2

I solved, the problem was in JRXML itself, when it takes the Fields through the query, in xml it generates such a field Description, and in this field Description comes blank, and it is in it that I need to put the same names my attributes of my application.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.