JS function not starting using PrimeFaces.monitorDownload

I work in uploading files using Primefaces 4.0 . I just want to run the JS function when the download is complete, but it doesn't seem to work (used in Firefox and Google Chrome). My test case is similar to what was done in 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]));
    }

}

A warning is triggered when the download starts, but not when the download finishes. Can anyone else try?

+4
source share
2 answers

this is a mistake .

The main error is in the FileDownloadActionListenerpackage org.primefaces.component.filedownload.

Line 65

externalContext.addResponseCookie(Constants.DOWNLOAD_COOKIE, "true", Collections.<String, Object>emptyMap());

Constants.DOWNLOAD_COOKIE - "primefaces.download", .

, PrimeFaces.monitorDownload Interval , cookie .

+8

, "" cookie.

'http://host/a/b/c', cookie ' ' '/a/b/c', , cookie, JavaScript, , '/a' (Chrome) '/a/' (Firefox). , 'primefaces.download', JavaScript .

, , "" cookie (.. cookie , ):

   ...
   FacesContext facesContext = FacesContext.getCurrentInstance();
   ExternalContext externalContext = facesContext.getExternalContext();
   Map<String, Object> map = new HashMap<String, Object>();
   map.put("path", "/a/");
   externalContext.addResponseCookie(Constants.DOWNLOAD_COOKIE, "true", map);
   ...

, , PrimeFaces.monitorDownload() cookie 'primefaces.download', null ', , Chrome Firefox cookie ( "/" Firefox), "" JS- cookie, :

   ...    
   document.cookie = 'primefaces.download=; path=/a/; expires=Thu, 01 Jan 1970 00:00:00 UTC';
   ...

, , cookie , .

+1

All Articles