Olá pessoal, boa tarde.
Estou precisando de uma ajuda na hora de imprimir um relatorio em PDF com 3 subreports.
O método funciona perfeitamente sem os subreports.
Já testei no iReport com os subreports e funciona perfeitamente. O problema é apenas na hora de passar os parâmetros no método.
segue o código:
[code] private String getDiretorioReal(String diretorio) {
HttpSession session = (HttpSession) FacesContext.getCurrentInstance()
.getExternalContext().getSession(false);
System.out.println(“getDireitorioReal”);
return session.getServletContext().getRealPath(diretorio);
}
private void preenchePdf(JasperPrint print) throws JRException {
saida = getDiretorioReal("/pdf/relatorio.pdf");
JasperExportManager.exportReportToPdfFile(print, saida);
saida = getContextPath() + "/pdf/relatorio.pdf";
}
private String getContextPath() {
HttpSession session = (HttpSession) FacesContext.getCurrentInstance()
.getExternalContext().getSession(false);
System.out.println("getContextPath");
return session.getServletContext().getContextPath();
}
public String imprimirRelatorio(ActionEvent event) throws Exception {
UIComponent link = event.getComponent();
UIParameter parametro = (UIParameter) link.findComponent("printCod");
Long id = (Long) parametro.getValue();
saida = null;
String jasper = getDiretorioReal("/jasper/pessoafisicaDC.jasper");
Connection conexao = null;
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) facesContext
.getExternalContext().getResponse();
ServletOutputStream servletOutputStream = response.getOutputStream();
try {
Connection con = new Conexao().getConexao();
Statement stm = con.createStatement();
String query = "SELECT escolaridade.descricao AS escolaridade_descricao, cargahorariasemanal.descricao AS cargahorariasemanal_descricao, cargo.descricao AS cargo_descricao, estados.uf AS estados_uf, municipiosrr.municipios AS municipiosrr_municipios, * FROM funcionario, municipiosrr, estados, cargo, escolaridade, cargahorariasemanal where cod_funcionario=" + id;
ResultSet rs = stm.executeQuery(query);
JRResultSetDataSource jrRS = new JRResultSetDataSource(rs);
Map map = new HashMap();
map.put("QUERY", con);
// PARAMETRO ADICIONADO PARA SUBREPORT
// map.put("SUBREPORT_DIR", con);
JasperPrint rel = JasperFillManager.fillReport(jasper, map, jrRS);
ByteArrayOutputStream output = new ByteArrayOutputStream();
JasperExportManager.exportReportToPdfStream(rel, output);
response.setContentType("application/pdf");
response.addHeader("Content-Disposition",
"attachment;filename=relatorio" + id + ".pdf");
response.setContentLength(output.size());
servletOutputStream.write(output.toByteArray(), 0, output.size());
servletOutputStream.flush();
servletOutputStream.close();
facesContext.responseComplete();
} catch (JRException e) {
e.printStackTrace();
} finally {
try {
if (conexao != null)
conexao.close();
} catch (Exception e) {
}
}
return "exibeRelatorio";
}[/code]
Agradeço a ajuda.