Download with 5.3 primefaces after 5.1 migration does not work

Asked

Viewed 278 times

3

I am migrating from primeface 5.1 to 5.3 . It was to be simple, just change the version in Maven.

But it’s not like that

The p:fileDownload command no longer works

<p:commandButton id="exportarArquivo" icon="ui-icon-print" value="Exportar arquivo" disabled="#{comissaoCobradorMB.isParametros()}" process="@this" > 
    <p:fileDownload value="#{comissaoCobradorMB.file}" />
</p:commandButton>

Debugging appears the following error in Browse(Chrome ).

Request Return with error:parsererror. primefaces.js.xhrml:1

Below the MB

The code is a little old but it worked.

Note that is generates a report. I checked and the same is generated.

public StreamedContent getFile() {
        geraRelatorio();
        return this.file;
    }


    private void geraRelatorio() {
        String path ;
        String nome ;
        String extensao;
        String pathReal ;
        String pathNome ;

        DateTimeFormatter fDataParaString = DateTimeFormatter.ofPattern("yyyyMMdd");
        DateTimeFormatter fDataParaStringData = DateTimeFormatter.ofPattern("dd/MM/yyyy");

        Map parametros = new LinkedHashMap();
        parametros.put("Data De" , fDataParaStringData.format(getDataInicial()));       //fDataParaString.format(this.getDataDe()) ) ;  
        parametros.put("Data Ate", fDataParaStringData.format(getDataFinal()));         // fDataParaString.format(this.getDataDe()) );

        extensao = "."+this.getTipoArquivo();
        path = "/WEB-INF/temporarios";
        nome = "comissaoCob";
        nome+="_De_"+fDataParaString.format(this.getDataInicial());
        nome+="_Ate_"+fDataParaString.format(this.getDataFinal());
        nome+="_Gr_";

        FacesContext facesContext = FacesContext.getCurrentInstance();  
        ServletContext servletContext = (ServletContext)facesContext.getExternalContext().getContext();
        pathReal  = servletContext.getRealPath(path);

        nome = Texto.nomePadrao(pathReal, nome, extensao);

        GeraArquivoTipo geraArquivoTipo;
        if(this.getTipoArquivo().trim().equals("PDF")){
            System.out.println(".............Entrou no PDF");
            geraArquivoTipo = GeraArquivoTipo.PDF;
        } else {
            geraArquivoTipo = GeraArquivoTipo.EXCEL;
            System.out.println(".............Entrou no Excel");
        }

        new RelatorioDeComissaoDeCobradores(comissao,pathReal.trim()+"/"+nome, parametros, geraArquivoTipo);

        pathNome = path+"/"+nome;
        InputStream stream = servletContext.getResourceAsStream(pathNome);            //getResourceAsStream(path+nome);
        //this.file = new DefaultStreamedContent(stream, "application/octet-stream", nome);
        this.file = new DefaultStreamedContent(stream,"application/pdf", nome);


    }
  • 1

    tries to put ajax="false" on the button

  • It worked Thanks. Can you tell why this behavior occurs?

  • I had trouble with the <p:schedule in this version 5.3 and had to go back to 5.0. See if nothing else broke in your application

1 answer

2


Browser other questions tagged

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