【发布时间】:2013-12-18 16:36:28
【问题描述】:
我正在使用 Primefaces 4.0 下载文件。我只想在下载完成时触发一个 JS 函数,但似乎不起作用(在 Firefox 和 Google Chrome 中尝试过)。我的测试用例看起来与PF docs 中所做的类似:
<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>
@ManagedBean
@ViewScoped
public class Bean implements Serializable {
public StreamedContent getFile() {
return new DefaultStreamedContent(new ByteArrayInputStream(new byte[0]));
}
}
下载开始时会触发警报,但下载完成时不会触发。其他人可以试试吗?
【问题讨论】:
-
同样,我遇到了递归 javascript 错误
Uncaught TypeError: Object function (e,b3){return new bI.fn.init(e,b3,w)} has no method 'cookie',这是一个 bug。
标签: jsf jsf-2 primefaces