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

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

问题描述

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

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 :Managed Bean

getDrawings():方法返回一个Drawing(实体类)列表

CheckedOutBy :实体属性绘图

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内部

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>

<p:push onpublish="javaScriptFunctionWhichUpdatesCheckedOutBy" />  

轮询很简单,但我可以想象它增加了不必要的开销。在同步下载开始时,您无法使用标准JSF / PrimeFaces组件启动它。但您可以阻止它对呈现的属性进行自检。推送在技术上是最好的解决方案,但更难以开始。 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天全站免登陆