Pass List to a sub report and call it in the main report

4

I have a method that generates a pdf report in a certain directory, now I need to use a sub report, but I have a hard time understanding how I can pass List as a data source to that sub relatório display it in the main report.

This is my method that generates the main report:

public boolean gerarRelatorio(List list, int numeroRelatorio, String nomePrestador, String dataSistema) {
        JasperReport report = null;
        InputStream image = this.getClass().getResourceAsStream("/br/com/xml/relatorio/LOGO.png");
        filtro.put("Image", image);
        try {

            InputStream inputStreamReal = getClass().getResourceAsStream("/br/com/xml/relatorio/Relatorio3.jrxml");
            report = JasperCompileManager.compileReport(inputStreamReal);
        } catch (JRException ex) {
            Logger.getLogger(frmPegaXml.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(null, "Erro ao pegar arquivos!", "ERRO!", JOptionPane.ERROR_MESSAGE);
        }
        try {

            JasperPrint print = JasperFillManager.fillReport(report, filtro, new JRBeanCollectionDataSource(list));
            JasperExportManager.exportReportToPdfFile(print,
                    "C:/Demonstrativos/" + dataSistema + "/" + nomePrestador + "_" + dataSistema + "_" + numeroRelatorio + ".pdf");

            /*Variaveis necessarias para salvar o Arquivo no Banco de dados*/
            caminho1 = "C:/Demonstrativos/" + dataSistema + "/";
            ext = ".zip";
            nomeArquivo1 = nomePrestador + "_" + dataSistema + "_" + numeroRelatorio;
            caminhoCompleto = caminho1 + nomeArquivo1 + ".pdf";

            codAP = Long.parseLong(codArquivoPrestador);
            relatoriosGerados = numeroRelatorio + 1;
            return true;
            /*Variaveis necessarias para salvar o Arquivo  no Banco de dados*/
        } catch (JRException ex) {
            Logger.getLogger(frmPegaXml.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(null, "Erro ao Gerar relatório, verifique se nenhum arquivo está aberto ou se o nome está correto!\n" + ex, "ERRO!", JOptionPane.ERROR_MESSAGE);
            return false;
        }

    }

- I tried to pass the list and path by parameter as follows:

filtro.put("listaDados", lista);
filtro.put("localizarRel", "src/br/com/xml/relatorio/subRelatorio.jasper");

But of this error:

15/05/21 10:36:25 ERROR fill.JRFillSubreport: Fill 1: exception
net.sf.jasperreports.engine.JRException: Error retrieving field value from bean : dataRealizacao

This Bean dataRealização is part of my sub Relatório , does anyone know where I might be going wrong?

    
asked by anonymous 20.05.2015 / 19:42

1 answer

1

Good morning! You have to create a parameter of type List in your report, the same has to be with the same name of the parameter that you are sending in code. Example:

filtro.put("listaDados", lista);

Create "DataList" in your report, then just send it to the subreport as follows:

new JRBeanCollectionDataSource (listData); in the dataset of your list, in the field "Use the JRDatasource expression" that you  should dial. In this case I can see that your report or subreport is not finding the dataRealizacao field, evaluates the object in your list, something is wrong with it. Hope this helps! Hugs!

    
25.06.2015 / 14:35