Jasperreport report - Blank page - PDF report

Asked

Viewed 760 times

1

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

But when I put to display in my JSF page the data is blank a blank pdf format .. Follows 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’d like your advice, please !!

  • in the params.put lines("cpf_Functioning" I’ve been searching .. are parameters .. there from Jasper and such.. and the invoice_logo was because apache was giving an error tbm on it.. there has been ,about an image of the report, guy already tested everything...

  • I removed the code from the first line. e tbm retirei params.put (invoice_log), even so the message of - _italic java.net.Malformedurlexception

  • someone to help me ??

  • hey guys.. I’m following a tutorial to export my report , and I don’t understand why it keeps giving error -- in this excerpt &#xA; String Caminho = Faces.getRealPath("default/ireport.jasper");

  • The parameters should be of the Map type. You can get a good reference by following the explanations of David Buzzato here: Working with Ireport

1 answer

0

Follows solution of the code:

Adjust 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();
  • 1

    It would be very important to have an explanation about the code!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.