Ace*_*unk 11 download primefaces jsf-2
我正在使用Primefaces TabView,CommandButton和FileDownload来下载日志文件.下载日志文件后,我想提供从服务器删除日志内容的选项.
最初,删除日志文件按钮(deleteEventLogButton)已禁用,并具有一个自定义标题,指出"删除日志 - 需要导出".导出日志后,应启用该按钮,标题应显示"删除日志".
我遇到的问题是仍然禁用删除日志文件按钮,即使在导出事件成功完成后,标题仍为"删除日志 - 需要导出".
我的猜测是在fileDownload值之前调用exportEventLogButton-> Update ="deleteEventLogButton".
一旦我导出了日志,我就可以点击'F5'并刷新页面并启用deleteEventLogButton以显示正确的标题.
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>
Run Code Online (Sandbox Code Playgroud)
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";
}
Run Code Online (Sandbox Code Playgroud)
我尝试在FileDownload中移动更新事件,但它没有什么区别.
<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>
Run Code Online (Sandbox Code Playgroud)
我现在已经搜索了几天,发现了许多与此问题非常接近的问题...但没有一个有帮助.:(
只是为了使事情变得清晰......我没有出口问题.问题是导出完成后未启用"删除日志文件"按钮.
par*_*lov 30
p:commandButton在你的情况下是(一个必须是)非AJAX按钮(你通过添加ajax="false"属性设置).在那种情况下,update属性和p:ajax标记没有任何意义(因为它们仅用于AJAX请求).下载文件后,您的应用程序会发送某种类型的流,然后您会看到" 保存文件"对话框.您的页面未刷新.所以你必须使用PrimeFaces.monitorDownload这样做:
<p:commandButton id="exportEventLogButton"
icon="ui-icon-disk"
styleClass="c25"
ajax="false"
title="Export Log"
disabled="#{empty managedCmsLogsBean.eventLogEntityList}"
onclick="PrimeFaces.monitorDownload(null, stop)">
Run Code Online (Sandbox Code Playgroud)
并添加将更新第二个按钮的停止功能:
<p:remoteCommand name="stop" update="deleteEventLogButton"/>
Run Code Online (Sandbox Code Playgroud)
小智 5
正如Balusc回答的那样,有问题(修订版)中,我们无法从单个请求中获得两次响应,要在下载后刷新页面,最好在下载链接(p:commandbutton)onclick标签中使用以下java脚本。
例子:
<p:commandButton ajax="false" icon="ui-icon-arrowstop-1-s" onclick="setTimeout('location.reload();', 1000);" action="#{managedBean.downloadMethod}" />
Run Code Online (Sandbox Code Playgroud)
这将在1秒后自动刷新页面,同时即在刷新之前,您将获得下载文件,根据您的下载响应时间,增加该脚本中的秒数。秒数不应小于下载响应时间。
| 归档时间: |
|
| 查看次数: |
14847 次 |
| 最近记录: |