2

I have a method that generates a pdf report sending a List as a data source and saves in a given directory, now it became necessary to use a sub report, but am having trouble understanding how I can pass a List as a data source for this sub report and then display it in the main report.

This is my method that generates the main report:

 public boolean generateReport(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/MainReport.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");
            return true;

        } 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 that way but it didn't work:

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

That was the exception:

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 dataRealizacao is part of my sub report, does anyone know where I might be missing?


Update Question: Class Procedimentos:

public class Procedimentos {

    private String numLote;
    private String dataRealizacao;
    private String descriçãoServico;
    private String codTab;
    private String codigoServico;
    private String quantidadeExecutada;
    private BigDecimal valorProcessado;
    private BigDecimal valorLiberado;
    private BigDecimal valorGlosa;
    private String codigoGlosa;
    private String sequenciaGuiaProcedimento;
    private String sequenciaGuiaDados;
    private String nomeBeneficiario;
    private String valorLiberadoGuia;
    ...

My SubReport: enter image description here

I have 2 parameters in my main report: listaDados (java.util.List) and localizarRel (java.lang.String) with expression default = "C: \ Users \ Adiego \ JaspersoftWorkspace \ MyReports \ subRelatorio.jasper"

And in my main report on the subreport properties I do it: enter image description here

Alex K
  • 22,315
  • 19
  • 108
  • 236
DiegoAugusto
  • 219
  • 3
  • 10

0 Answers0