我使用Primefaces TabView、CommandButton和FileDownload下载日志文件。下载日志文件后,我希望提供从服务器删除日志内容的选项。
最初,删除日志文件按钮(deleteEventLogButton)被禁用,并有一个自定义标题,说明“删除日志-导出必需”。一旦日志被导出,按钮应该被启用,标题应该声明"Delete Logs“。
我遇到的问题是,仍然是禁用的,即使在Export成功完成之后,标题仍然是"Delete“。
我猜exportEventLogButton->Update="deleteEventLogButton“是在fileDownload值之前被调用的。
一旦导出了日志,我就可以点击'F5‘并刷新页面,deleteEventLogButton就可以显示正确的标题了。
JSF -片段
<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>
支持Bean -片段
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";
}
我尝试将更新事件移到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>
我已经找了几天了,发现了很多问题,这些问题非常接近这个.但谁也帮不上忙。:(
只是为了让事情更清楚..。我的出口没有问题。问题是在导出完成后,没有启用Delete日志文件按钮。
发布于 2013-04-01 06:23:54
在您的示例中,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)">
并添加停止功能,它将更新第二个按钮:
<p:remoteCommand name="stop" update="deleteEventLogButton"/>
发布于 2015-04-08 21:22:10
发布于 2021-09-24 06:24:52
您可以从PrimeFaces 10下载带有 ajax="true"
的文件。这也允许您更新组件。
另请参阅:
https://stackoverflow.com/questions/15744778
复制相似问题