从JSF下载文件并显示响应 [英] File download from JSF with a rendered response

查看:124
本文介绍了从JSF下载文件并显示响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些动态生成的文件,需要我的JSF 2.0应用程序下载给用户.我已经能够使用此处的解决方案中的代码使此工作正常进行:

I have some dynamically generated files which I want my JSF 2.0 app to download for the user. I've been able to get this working using the code found in the solution here :

强制通过JSF应用程序从任何Web浏览器进行另存为对话

和页面上的表单中的命令按钮

and a command button in a form on the page

那很好,除了一个结.我希望能够在初始页面上向用户呈现一条消息,告诉他们他们的文件正在处理中,请稍候.显然,responseComplete调用阻止了这种情况的发生.有什么方法可以重新渲染提交页面并从同一按钮发送回文件?

And that works fine except for one hitch. I'd like to be able to render a message back to the user on the initial page that tells them their file is being processed and to please wait. Obviously the responseComplete call stops that from happening. Is there some way to re-render the submitting page and send back a file from the same button?

推荐答案

不,您不能.每个请求只能发送回一个响应.最好的办法是使用JavaScript来显示最初隐藏的div或在onclick期间包含消息的内容.但是您会遇到一个问题,一旦下载完成,您将无法隐藏它.

No, you can't. You can send only one response back per request. Best what you could do is to use JavaScript to show an initially hidden div or something which contains the message during the onclick. But you'll have the problem that you cannot hide it whenever the download is completed.

另一种选择是将文件存储在临时磁盘上,并返回完全有价值的JSF响应,其中显示一个下载链接,该链接通过独立的servlet从临时磁盘返回文件.

An alternative is to store the file on temp disk and return a fullworthy JSF response wherein you display a download link which returns the file from temp disk by a standalone servlet.

这篇关于从JSF下载文件并显示响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆