Try this:
Declare an attribute of type DefaultStreamedContent
in your bean:
Example:
private DefaultStreamedContent download;
Do the Get and Sets:
public DefaultStreamedContent getDownload() {
return download;
}
public void setDownload(DefaultStreamedContent download) {
this.download = download;
}
Next :
//Método que faz o download do anexo
public void prepDownload() throws Exception {
File file = new File("c:/tmp/arquivo.pdf");
InputStream input = new FileInputStream(file);
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
setDownload(new DefaultStreamedContent(input, externalContext.getMimeType(file.getName()), file.getName()));
}
Then on your button;
<p:commandButton icon="ui-icon-arrowthickstop-1-s"
title="Download Anexo"
actionListener="#{bean.prepDownload()}"
ajax="false">
<p:fileDownload value="#{bean.download}" />
</p:commandButton>