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

Asked

Viewed 738 times

4

Guys I have a method that generates a pdf report in a certain directory, now arose the need to use a sub report, but I’m having difficulty understanding how to pass a List as the data source for this sub relatório and then display it in the main report.

That 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 the path by parameter as follows:

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

But make that mistake:

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

Esse Bean dataRealização is part of my sub Relatório, some know where I might be missing?

  • Can someone help me?

  • The answer to this question can be found in this question, which I have already answered for some time: http://answall.com/questions/32955/fill_report_com-nestedlists :the)

1 answer

1


Good morning! You have to create a List parameter in your report, it must have the same name as the parameter you are sending in code. Example:

filtro.put("listaDados", lista);

Create "list" in your report, then just send it to the sub-report like this:

new Jrbeancollectiondatasource(listed); in the dataset of your list, in the "Use Jrdatasource Expression" field you should mark. In this case I can see that your report or sub-report is not finding the field dataRealizacao, There’s something wrong with it. I hope I helped! Hug!

Browser other questions tagged

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