使用PrimeFaces.monitorDownload不会触发JS函数

Xtr*_*ica 4 jsf primefaces jsf-2

我正在使用Primefaces 4.0进行文件下载.我只想在下载完成时触发JS功能,但似乎无法工作(在Firefox和谷歌浏览器中尝试过).我的测试用例看起来类似于PF文档中的操作:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">
<h:head />

<h:body>
    <script type="text/javascript">
        function startMessage() {
            alert("Download started!");
        }
        function finishMessage() {
            alert("Download finished!");
        }
    </script>
    <h:form>
        <p:commandButton value="Download" ajax="false"
            icon="ui-icon-arrowreturnthick-1-s"
            onclick="PrimeFaces.monitorDownload(startMessage, finishMessage)">
            <p:fileDownload value="#{bean.file}" />
        </p:commandButton>
    </h:form>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
@ManagedBean
@ViewScoped
public class Bean implements Serializable {

    public StreamedContent getFile() {
        return new DefaultStreamedContent(new ByteArrayInputStream(new byte[0]));
    }

}
Run Code Online (Sandbox Code Playgroud)

下载开始时会触发警报,但下载完成时则不会触发警报.还有其他人可以尝试一下吗?

Hat*_*mam 8

这是一个错误.

主要错误是在FileDownloadActionListenerorg.primefaces.component.filedownload包.

第65行

externalContext.addResponseCookie(Constants.DOWNLOAD_COOKIE, "true", Collections.<String, Object>emptyMap());
Run Code Online (Sandbox Code Playgroud)

Constants.DOWNLOAD_COOKIE是"primefaces.download",它永远不会与响应一起发送.

这将导致PrimeFaces.monitorDownloadInterval永远不会调用stop函数,因为cookie永远不会被写入.