O 'a4j:commandButton' não faz download. Quer dizer, até pode fazer, mas euzinha desconheço como.
Tentei fazer um 'h:commandButton' com 'a4j:support' no onComplete, mas não funciona. Então, recebi a sugestão ao contrário, onde o 'a4j:commandButton' chama o 'h:commandButton'. Funciona que é uma beleza.
<a4j:commandButton id="btnAjax" value="Atualiza a tela e faz download" action="#{mBeanWhateva.fazAcao}" oncomplete="jQuery('[id$=btnDownload]').click()" reRender="o,que,vc,quiser"/>
<h:commandButton id="btnDownload" value="Faz o Download apenas" action="#{mBeanWhateva.fazDownload}" style="display:none"/>
<h:commandButton id="btnDownload" value="Faz o Download apenas" action="#{mBeanWhateva.fazDownload}" style="display:none"/>
public String finalizarSetup() {
// faz muita coisa
return null;
}
public String fazDownload() throws Exception {
ByteArrayOutputStream meusDadosdoRelatorio = gerarRelatorio(); // do the trick
FacesContext context = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
response.setContentType("application/force-download");
response.setHeader("Content-Disposition","attachment; filename=nomeDoArquiv.extensao");
OutputStream sos;
sos = response.getOutputStream();
sos.write(meusDadosdoRelatorio.toByteArray());
sos.flush();
sos.close();
context.responseComplete();
return null;
}
// faz muita coisa
return null;
}
public String fazDownload() throws Exception {
ByteArrayOutputStream meusDadosdoRelatorio = gerarRelatorio(); // do the trick
FacesContext context = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
response.setContentType("application/force-download");
response.setHeader("Content-Disposition","attachment; filename=nomeDoArquiv.extensao");
OutputStream sos;
sos = response.getOutputStream();
sos.write(meusDadosdoRelatorio.toByteArray());
sos.flush();
sos.close();
context.responseComplete();
return null;
}
Nenhum comentário:
Postar um comentário