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?
– DiegoAugusto
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)
– wryel