试图让一个简单的文件下载工作,我得到的只是一个悬挂的 AJAX 状态栏,就是这样。我的支持 bean 输出在准备和下载时呈现正确的名称。
我做错了吗?在我看来,这两个输出都是正确的。
JSF 2.0 Primefaces 3.4
<h:form>
<p:commandButton id="downloadLink" value="Download" actionListener="#{filemanagement.prepDownload}">
<p:fileDownload value="#{filemanagement.download}" />
</p:commandButton>
</h:form>
支持豆:
private DefaultStreamedContent download;
public void setDownload(DefaultStreamedContent download) {
this.download = download;
}
public DefaultStreamedContent getDownload() throws Exception {
System.out.println("GET = " + download.getName());
return download;
}
public void prepDownload() throws Exception {
File file = new File("C:\\file.csv");
InputStream input = new FileInputStream(file);
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
setDownload(new DefaultStreamedContent(input, externalContext.getMimeType(file.getName()), file.getName()));
System.out.println("PREP = " + download.getName());
}