Good morning, I have a small problem. I am trying to pass lista
as data source
to my sub report. I already have the main report which is also populated by a list. My question is, how do I pass a lista
as data source
to my sub report and then call that sub report within my main report?
This is my method that generates the report and exports in pdf to a directory:
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/Relatorio2.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'm using JasperSoft Studio, thank you.