我正面临使用Primefaces monitorDownload(PF 3.4.2)。
我想创建一个文件并使用commandButton下载它。单击该按钮,在启动功能后立即触发停止功能。然后正确完成生成+下载请求。所以end函数不会在下载结束时触发,而是在开始时,与start函数相同的时刻触发。
不是我想要的。我想这个场景:
我的代码:
<h:form>
<pf:panel>
<pf:commandButton value="Export database" id="exportDatabase" ajax="false" onclick="PrimeFaces.monitorDownload(window.alert('start'), window.alert('stop'));">
<pf:fileDownload value="#{bean.exportDatabase()}" />
</pf:commandButton>
</pf:panel>
</h:form>
豆方:
private StreamedContent exportDatabaseFile;
public StreamedContent exportDatabase() {
String exportDatabaseFilename = "nameOfTheFile.xlsx";
Path nameExportDatabasePath = "C:\nameOfTheFile.xlsx";
// Populate exportDatabaseFile
exportDatabaseFile = new DefaultStreamedContent(new FileInputStream(nameExportDatabasePath.toFile()), FacesContext.getCurrentInstance().getExternalContext().getMimeType(exportDatabaseFilename), exportDatabaseFilename);
return exportDatabaseFile;
}
如何解决这个问题?
答案 0 :(得分:0)
尝试使用
私有StreamedContent exportDatabaseFile;
public StreamedContent exportDatabase() {
String exportDatabaseFilename = "nameOfTheFile.xlsx";
Path nameExportDatabasePath = "C:\nameOfTheFile.xlsx";
// Populate exportDatabaseFile
return new DefaultStreamedContent(new FileInputStream(nameExportDatabasePath.toFile()), FacesContext.getCurrentInstance().getExternalContext().getMimeType(exportDatabaseFilename), exportDatabaseFilename);
}