带有对话框和加载状态的 p:fileDownload 策略
p:fileDownload
的策略,带有加载
I 的 对话框我正在尝试在开始下载文件后制作一个加载栏。我的下载按钮是这样的:
<p:commandButton id="btnFirstType"
styleClass="bt_princ"
value="Download File"
onclick="loading.show()"
ajax="false">
<p:fileDownload value="#{mbean.myFile}"/>
</p:commandButton>
<p:dialog modal="true"
widgetVar="loading"
header="Status"
draggable="false"
closable="false">
<p:graphicImage value="/loading.gif" />
</p:dialog>
我的 MBean 是这样的:
public StreamedContent getMyFile(){
return this.getReport(Type.CSV); //I assure this works, debugged...
}
问题是,单击下载按钮后,如果我启动加载对话框,则不会发生下载。 我考虑过使用 p:poll
来检查一个布尔变量,这样我就知道文件何时生成,这样我就可以在单击按钮后显示对话框(就像使用 JavaScript 设置 setTimeout
一样),但这可能是我对整个事情的错误发生。还有其他建议吗?
PS1:文件下载后轮询停止工作,所以我不知道什么时候关闭dialod
PS2:我使用的是Primefaces 2.2,无法更新。
PS3:找到这个解决方法,但“它将”出现在版本3上,所以我不能使用它。
Strategy for p:fileDownload
with dialog with loading
I am trying to make a loading bar after starting the download of a file. My download button is like this:
<p:commandButton id="btnFirstType"
styleClass="bt_princ"
value="Download File"
onclick="loading.show()"
ajax="false">
<p:fileDownload value="#{mbean.myFile}"/>
</p:commandButton>
<p:dialog modal="true"
widgetVar="loading"
header="Status"
draggable="false"
closable="false">
<p:graphicImage value="/loading.gif" />
</p:dialog>
And my MBean is like this:
public StreamedContent getMyFile(){
return this.getReport(Type.CSV); //I assure this works, debugged...
}
The problem is, after clicking the download button, if I start the loading dialog, the download doesn't occurr.
I thought about using p:poll
to check a boolean variable so I know when the file has been generated, so I could show the dialog after clicking the button (like setting setTimeout
with JavaScript), but this is maybe my mistake about how the whole thing happens. Any other suggestion?
PS1: Polling stops working after the file is downloaded, so I won't know when to close the dialod
PS2: I am using Primefaces 2.2 and can't update.
PS3: Found this workaround but 'it will' be on version 3, so I can't use it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我按照我的问题中发布的解决方法中的建议进行了相同的操作。
我从我的版本下载了 primefaces 源代码,更改了 FileDownloadActionListener 类,在响应对象中添加了 cookie,在我的页面中,我刚刚启动了一个使用 setTimeout 的进程,该进程将每 100 毫秒检查一次 cookie,并在找到它时将其删除。
I did the same as suggested in the workaround posted on my question.
I downloaded the primefaces sources from my version, changed the FileDownloadActionListener class, added cookies in the response object and in my page I just started a process with setTimeout that would check cookies every 100 miliseconds, and when find it, delete it.