我可以在非ajax primefaces动作的文件响应后执行javascript吗?

问题描述 投票:0回答:1

我在primefaces应用程序中有一个表单,它调用来自辅助bean的操作,操作响应一个文件,供用户使用outputStream下载。

在客户端,我有一个虚假的提交命令按钮,带有onclick事件处理程序,触发显示微调器的javascript,然后单击隐藏的“实际”提交命令按钮,该命令按钮调用响应该文件的支持bean操作。

一旦我收到回复,我想隐藏微调器。

我知道如果我希望服务器用文件响应,我必须使用ajax = false。但后来我不能使用oncomplete监听器。

一旦我在客户端获得响应,是否有任何解决方案/解决方法可以触发一些javascript?我在网上发现了一些旧的论坛帖子,但没有一个包含可行的。

// The buttons and spinner
<i class="fa fa-spin fa-spinner" id="spinner" style="display:none;"/>
<p:commandButton widgetVar="fakeSubmitButton" type="button" value="Submit" onclick="submit9);" ajax="false" /> 
<p:commandButton widgetVar="actualSubmitButton" type="submit" action="#{testController.respondWithFile}" value="" style="display:none;" ajax="false"/> 

// ... and the two javascript functions 
function submitReport() {
    $('#spinner').show();
    PF('actualSubmitButton').getJQ().click();
}           
function postSubmitReport() {
    $('#spinner').hide();
}

// ... and on the server side I respond with a file by grabbing the ExternalContext from the FacesContext and using its outputStream.
javascript http jsf primefaces
1个回答
1
投票

如果有更好的选择,我仍然希望听到它们,但是我找到了一种方法来实现我想要的行为,使用类似于展示示例的p:fileDownload:https://www.primefaces.org/showcase/ui/file/download.xhtml。在服务器端,我的代码相对没有变化,除了使用ExternalContext的输出流返回响应文件,我正在构建一个StreamedContent,它从fileDownload小部件调用的函数返回。

© www.soinside.com 2019 - 2024. All rights reserved.