下载后如何刷新页面 [英] How to refresh a page after download

查看:53
本文介绍了下载后如何刷新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个命令按钮,它将调用一个函数来下载一个文件(标准的东西,如 InputStreamBufferedOutputStream ...)下载成功后,在函数,我更改当前对象的一些值并将其持久化到数据库中.所有这些都可以正常工作.现在当文件下载完成时,页面的内容不会更新.我必须点击刷新才能看到更新的内容.请帮忙.下面是我的代码的基本结构

I have a commandButton that will invoke a function to download a file (standard stuffs like InputStream, BufferedOutputStream ...) After download success, at the end of the function, I change some values of the current object and persist it into database. All of these work correctly. Now when file is done downloading, the content of the page is not updated. I have to hit refresh for me to see updated content. Please help. Below are the basic structure of my code

document:托管 Bean
getDrawings():方法返回Drawing(实体类)列表
CheckedOutBy:实体Drawing

document: Managed Bean
getDrawings(): method return a list of Drawing (entity class)
CheckedOutBy: attribute of Entity Drawing

<p:dataTable id="drawing_table" value="#{document.drawings}" var="item" >                            
    <p:column>
        <f:facet name="header">
              <h:outputText value="CheckedOutBy"/>
        </f:facet>
        <h:outputText value="#{item.checkedOutBy}"/>
        ...
</p:dataTable>
<p:commandButton ajax="false" action="#{document.Download}" value="Download" />

在我的托管 Bean 中

Inside my Managed Bean

public void Download(){
    Drawing drawing = getCurrentDrawing();
    //Download drawing
    drawing.setCheckedOutBy("Some Text");
    sBean.merge(drawing);  //Update "Some Text" into CheckedOutBy field
}

推荐答案

您基本上希望让客户端触发两个请求.一个用于检索下载,另一个用于刷新新页面.它们不能在单个 HTTP 请求中完成.由于下载需要同步进行,并且无法从客户端挂钩下载完成,因此没有干净的 JSF/JS/Ajax 方法在下载完成时更新组件.

You'd basically like to let the client fire two requests. One to retrieve the download and other to refresh the new page. They cannot be done in a single HTTP request. Since the download needs to be taken place synchronously and there's no way to hook on complete of the download from the client side on, there are no clean JSF/JS/Ajax ways to update a component on complete of the download.

在 PrimeFaces 的帮助下,您最好的 JSF 投注是 <p:poll>

Your best JSF-bet with help of PrimeFaces is <p:poll>

<h:outputText id="checkedOutBy" value="#{item.checkedOutBy}"/>
...
<p:poll id="poll" interval="5" update="checkedOutBy" />

<p:push onpublish="javaScriptFunctionWhichUpdatesCheckedOutBy" />  

轮询很容易,但我可以想象它会增加不必要的开销.当同步下载开始时,您不能使用标准 JSF/PrimeFaces 组件启动它.但是您可以停止它,让它对 rendered 属性进行自检.推动是技术上最好的解决方案,但更难开始.PrimeFaces 在用户指南的第 6 章中很好地解释了它的用法.

Polling is easy, but I can imagine that it adds unnecessary overhead. You cannot start it using standard JSF/PrimeFaces components when the synchronous download starts. But you can stop it to let it do a self-check on the rendered attribute. Pushing is technically the best solution, but tougher to get started with. PrimeFaces explains its use however nicely in chapter 6 of the User Guide.

这篇关于下载后如何刷新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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