JSF后台Bean执行文件下载后无法隐藏加载动画的问题求助
JSF后台Bean执行文件下载后无法隐藏加载动画的问题求助
我现在碰到个头疼的问题:我能实现文件下载功能,也能正常显示加载动画,但下载完成后加载动画死活没法隐藏。我猜是FacesContext.getCurrentInstance().responseComplete();这行代码阻止了UI重新渲染导致的。
有没有大佬能给点解决思路?
下面是相关代码:
后台Bean代码
public String downloadStatistics(String serviceId) { ServiceTotal serviceTotal = getStat(serviceId); String tmpFolderPath = configuration.getWorkspace() + File.separator + TemporaryFolderNames.STATISTICS.getValue(); try { if (serviceTotal != null && FileUtilFactory.getInstance().createPath(tmpFolderPath)) { File tmpFolder = new File(tmpFolderPath); File pdf = createStatisticPdf.createReportingPdf(tmpFolder, serviceTotal.getDocuments(), false); facesUtils.runJavaScriptMethod(HIDE_LOADING_ANIMATION_METHOD); jsfDownloader.downloadFile(pdf); } } catch (Exception e) { showErrorMessage("Could not download statistics", e); } return VIEW_NAME; } public void downloadFile(File file) throws IOException { FileUtilFactory.getInstance().readFileIntoOutputStream(getOutputStream(file), file); FacesContext.getCurrentInstance().responseComplete(); }
前端页面代码
<h:commandLink id="link_stats2" action="#{statisticsViewModel.downloadStatistics(statisticsViewModel.currentStat.id)}" onclick="showLoadingAnimation('loading-animation-download')" styleClass="btn btn-default"> Download </h:commandLink> <img id="loading-animation-download" src="images/anim.gif" style="display:none" alt="waiting indicator"/>
我已经尝试过这些方法,但都没效果:
- 在调用
FacesContext.getCurrentInstance().responseComplete();之前就执行隐藏动画的代码 - 让方法返回视图名称
VIEW_NAME - 排查过哪行代码导致的问题,有意思的是,
downloadFile方法里的两行代码,不管注释掉哪一行,都会阻止动画隐藏
备注:内容来源于stack exchange,提问作者Luca Christ
相关产品推荐
相关产品推荐

