文件下载后更新组件 [英] Update component after file download

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

问题描述

我使用的是Primefaces TabView,CommandButton和FileDownload来下载一个日志文件。一旦下载了日志文件,我想提供从服务器中删除日志内容的选项。



最初删除日志文件按钮(deleteEventLogButton)是禁用并具有说明删除日志 - 需要导出的自定义标题。一旦日志导出,该按钮应该被启用,标题应该说明删除日志。



我遇到的问题是删除日志文件按钮仍然禁用,即使在导出事件成功完成后,标题也显示为删除日志 - 导出必需。



我的猜测是exportEventLogButton-> Update =deleteEventLogButton 在文件下载值之前被调用。



导出日志后,我可以点击F5刷新页面,并启用deleteEventLogButton,显示正确的



JSF - Snippet

 < p:tabView id =logView> 
< p:tab id =eventLogTabtitle =安全事件>
< p:panelGrid ...>

< p:commandButton id =exportEventLogButtonicon =ui-icon-diskstyleClass =c25ajax =falsetitle =导出日志disabled =#{empty managedCmsLogsBean .eventLogEntityList}update =deleteEventLogButton>
< p:fileDownload value =#{managedCmsLogsBean.exportEventLogFiles()}/>
< / p:commandButton>

< p:commandButton id =deleteEventLogButtonicon =ui-icon-trashstyleClass =c25ajax =falsetitle =#{managedCmsLogsBean.deleteEventLogCaption}disabled = #{!managedCmsLogsBean.eventLogExported}action =#{managedCmsLogsBean.clearEventLogs()}update =eventLogTab/>

< / p:panelGrid>

< p:dataTable value =#{managedCmsLogsBean.eventLogEntityList}...>
...
< / p:dataTable>

< / p:tab>
< / p:tabView>

Backing Bean - Snippet

  private boolean eventLogExported; 

public StreamedContent exportEventLogFiles(){
eventLogExported = true;
return logFileUtility.exportSecurityEventLog(eventLogEntityList,eventLogStartDate,eventLogStopDate);
}

public boolean isEventLogExported(){
return eventLogExported;
}

public void setEventLogExported(boolean value){
eventLogExported = value;
}

public String getDeleteEventLogCaption(){
return eventLogExported? 删除日志:删除日志 - 导出必需;
}

我尝试移动FileDownload中的更新事件,但没有一个差异。

 < p:commandButton id =exportEventLogButtonicon =ui-icon-diskstyleClass =c25 ajax =falsetitle =导出日志disabled =#{empty managedCmsLogsBean.eventLogEntityList}> 
< p:fileDownload value =#{managedCmsLogsBean.exportEventLogFiles()}>
< p:ajax update =deleteEventLogButton/>
< / p:fileDownload>
< / p:commandButton>

我已经搜索了几天,发现很多问题都非常接近一个...但没有一个有帮助。 :(



只是为了使事情非常清楚...我没有导出问题,问题是删除日志文件按钮在导出后未启用完成。

解决方案

p:commandButton 必须)非AJAX按钮(您通过添加 ajax =false属性)设置此选项。在这种情况下 update 属性和 p:ajax 标签没有任何意义(因为它们只适用于AJAX请求)当您有文件下载时,应用程序会发送某种类型的流,您将看到保存文件对话框,您的页面不会刷新,因此您必须使用 PrimeFaces.monitorDownload 来执行此操作:




$ b styleClass =c25
ajax =ui-icon-disk
styleClass =c25
ajax = false
title =Export Log
disabled =#{empty managedC msLogsBean.eventLogEntityList}
onclick =PrimeFaces.monitorDownload(null,stop)>

并添加停止功能,将更新第二个按钮:

 < p:remoteCommand name =stopupdate =deleteEventLogButton/> 


I'm using Primefaces TabView, CommandButton and FileDownload to download a log file. Once the log file has been downloaded, I want to offer the option to delete the contents of the log from the server.

Initially the Delete Log File Button (deleteEventLogButton) is disabled and has a custom caption stating "Delete Logs - Export Required". Once the log has been exported, the button should be enabled and the caption should state "Delete Logs".

The problem that I'm having is that the Delete Log File Button is still disabled and the caption reads "Delete Logs - Export Required" even after the Export event completes successfully.

My guess is that the exportEventLogButton->Update="deleteEventLogButton" is being called before the fileDownload value.

Once I've exported the logs, I can hit 'F5' and refresh the page and the deleteEventLogButton is enabled showing the correct caption.

JSF - Snippet

<p:tabView id="logView">
    <p:tab id="eventLogTab" title="Security Events">
        <p:panelGrid ...>

            <p:commandButton id="exportEventLogButton" icon="ui-icon-disk" styleClass="c25" ajax="false" title="Export Log" disabled="#{empty managedCmsLogsBean.eventLogEntityList}" update="deleteEventLogButton">
                <p:fileDownload value="#{managedCmsLogsBean.exportEventLogFiles()}"/>
            </p:commandButton>

            <p:commandButton id="deleteEventLogButton" icon="ui-icon-trash" styleClass="c25" ajax="false" title="#{managedCmsLogsBean.deleteEventLogCaption}" disabled="#{! managedCmsLogsBean.eventLogExported}" action="#{managedCmsLogsBean.clearEventLogs()}" update="eventLogTab" />    

        </p:panelGrid>

        <p:dataTable value="#{managedCmsLogsBean.eventLogEntityList}" ...>
            ...
        </p:dataTable>

    </p:tab>
</p:tabView>

Backing Bean - Snippet

private boolean eventLogExported;

public StreamedContent exportEventLogFiles() {
    eventLogExported = true;
    return logFileUtility.exportSecurityEventLog(eventLogEntityList, eventLogStartDate, eventLogStopDate);
}

public boolean isEventLogExported() {
    return eventLogExported;
}

public void setEventLogExported(boolean value) {
    eventLogExported = value;
}

public String getDeleteEventLogCaption() {
    return eventLogExported ? "Delete Logs" : "Delete Logs - Export Required";
}

I tried moving the update event inside the FileDownload, but it didn't make a difference.

<p:commandButton id="exportEventLogButton" icon="ui-icon-disk" styleClass="c25" ajax="false" title="Export Log" disabled="#{empty managedCmsLogsBean.eventLogEntityList}">
    <p:fileDownload value="#{managedCmsLogsBean.exportEventLogFiles()}">
        <p:ajax update="deleteEventLogButton"/>
    </p:fileDownload>
</p:commandButton>

I've searched for a couple of days now and have found MANY problems that come very close to this one... but none that have helped. :(

Just to make things very clear... I am NOT having problems with the export. The problem is that the Delete Log File Button is not enabled after the export is complete.

解决方案

p:commandButton in your case is (an has to be) non-AJAX button (you set this by adding ajax="false" attribute). In that case update attribute and p:ajax tag doesn't have any sense (as they are only for AJAX requests). When you have file download your application sends streaming of some type, and you see Save File dialog. You page is not refreshed. So you have to use PrimeFaces.monitorDownload to do this:

<p:commandButton id="exportEventLogButton" 
                 icon="ui-icon-disk" 
                 styleClass="c25" 
                 ajax="false" 
                 title="Export Log" 
                 disabled="#{empty managedCmsLogsBean.eventLogEntityList}"
                 onclick="PrimeFaces.monitorDownload(null, stop)">

and add stop function which will update second button:

<p:remoteCommand name="stop" update="deleteEventLogButton"/>

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

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