2017-02-15 75 views
0

非常相似,Show status on start of p:fileDownload and hide status when it is finished顯示狀態:當它完成出口國和隱藏狀態

但在這種情況下,我有一個是花費很長的時間來導出數據表,所以我需要的是PE:導出器在用戶單擊導出按鈕時顯示微調器或狀態,並在導出文件發送回客戶端時將其隱藏。

目前我導出按鈕看起來像:

<h:commandLink style="float:right;padding:3px;margin-top:2px;" immediate="true" 
 
    styleClass="fa fa-file-pdf-o" title="Export to PDF"> 
 
    <pe:exporter type="pdf" encoding="iso-8859-1" target="datatable" 
 
    fileName="ExportResult"/> 
 
</h:commandLink>

我Primefaces 6.0

+0

您是否嘗試使用Ajax狀態?!? –

+0

這裏沒有涉及到的ajax ...如果我明白你的問題,你正在搜索的東西,使得像一個加載狀態是你正在尋找什麼?出口商作出標準的POST http請求 –

+0

? –

回答

0

好,我已經找到了解決辦法。

<h:commandLink style="float:right;padding:3px;margin-top:2px;" immediate="true"   styleClass="fa fa-file-pdf-o" title="Export to PDF" 
 
    onclick="PrimeFaces.monitorDownload(startHandler, endHandler)"> 
 
    <pe:exporter type="pdf" encoding="iso-8859-1" target="dataTable" 
 
    fileName="resultadoConsulta"/> 
 
</h:commandLink>

請注意onclick="PrimeFaces.monitorDownload(startHandler, endHandler)"部分。

這是解決方案的第一部分。 startHandler和endHandler是顯示和隱藏微調器的javascript函數,就像p:fileDownload showcase中的微調器一樣。

第二部分是棘手的。我有一個自定義的出口商和失蹤的響應這一行:

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

這行代碼設置一個Primefaces的monitorDownload功能期待的標誌。

之後,所有的工作!