0
Good morning guys, I’m having a little problem. I’m trying to pass a lista
as data source
for my sub report. I already have the main report which is also filled in by a list. My question is this, how do I pass one lista
as data source
for 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 so much.
The answer of the colleague above is correct, it is the best way to do it, just complement saying that it does not necessarily need to be a parameter, you can also pass a field of your main data source, as long as this is a list.
– Lucas Boeing Scarduelli