JasperReport Report - Blank Page - PDF Report

2

This is the following I created the report in jasperReport I created a parameter there, with that the data of this report it is getting from the bank (Mysql) and displaying /

But when I post to display on my JSF page the data is blank in a blank pdf format. Follow my code

In the apache server console, displays this message ...

  

Caused by: java.net.MalformedURLException

public RelatorioBean() {
    this.context = FacesContext.getCurrentInstance();
    this.response = (HttpServletResponse) context.getExternalContext().getResponse();
}

public void exporterPdf() {

    stream = this.getClass().getResourceAsStream("/Ireport/ireport_1.jrxml");
    Map<String,Object> params = new HashMap<String,Object>();
    params.put("cpf_Funcionario",params);
    params.put("invoice_logo",params);
    baos = new ByteArrayOutputStream();

    try {

         JasperReport report = JasperCompileManager.compileReport(this.getClass().getResourceAsStream("/Ireport/ireport_1.jrxml" ));          
        JasperPrint print = JasperFillManager.fillReport(report,params, Conexao.getConexao());
        JasperExportManager.exportReportToPdfStream(print, baos);            
       JasperViewer view = new JasperViewer(print,false);
        view.setExtendedState(JasperViewer.MAXIMIZED_BOTH);
        view.setVisible(true);




        response.reset();
        response.setContentType("application/pdf");
        response.setContentLength(baos.size());
                                                    //attachment
        response.setHeader("Content-disposition","inline;filename=ireport.pdf");
        response.getOutputStream().write(baos.toByteArray());
        response.getOutputStream().flush();
        response.getOutputStream().close();
        context.responseComplete();

    } catch (JRException ex) {

        Logger.getLogger(RelatorioBean.class.getName()).log(Level.SEVERE, null, ex);
         JOptionPane.showMessageDialog(null, "Falha ao exportar: " + ex.getMessage(), "Erro", JOptionPane.ERROR_MESSAGE);
    } catch (IOException ex) {
        Logger.getLogger(RelatorioBean.class.getName()).log(Level.SEVERE, null, ex);
       JOptionPane.showMessageDialog(null, "Falha ao exportar: " + ex.getMessage(), "Erro", JOptionPane.ERROR_MESSAGE);


    }     

I would like your advice, kindly !!

    
asked by anonymous 31.08.2016 / 21:03

1 answer

0

Here is the code solution:

Adjustment according to your needs:

this.context = FacesContext.getCurrentInstance();
this.response = (HttpServletResponse) context.getExternalContext().getResponse();

String caminho;
Map<String, Object> parametros = new HashMap<>();
baos = new ByteArrayOutputStream();
try {
if ("nao".equals(relatorio.getGeral()) && "periodo".equals(relatorio.getTipoDeRelatorio())) {

caminho = Faces.getRealPath("/reports/vendas/vendas.jasper");

parametros.put("Id_Cliente_Venda", relatorio.getCliente().getCodigo());
parametros.put("data_inicio", relatorio.getDataInicial());
parametros.put("data_fim", relatorio.getDataFinal());
parametros.put("CodEmpresa", autenticacaoBean.getUsuario().getEmpresa().getCodigo());

//JasperReport report = (JasperReport) JRLoader.loadObject(caminho);
JasperPrint print = JasperFillManager.fillReport(caminho, parametros, conexao);
JasperExportManager.exportReportToPdfStream(print, baos);

response.reset();
response.setContentType("application/pdf");
response.setContentLength(baos.size());
response.setHeader("Content-disposition", "inline; filename=relatorio.pdf");
response.getOutputStream().write(baos.toByteArray());
response.getOutputStream().flush();
response.getOutputStream().close();

context.responseComplete();
    
01.02.2018 / 21:01