我无法下载该zip文件。在confirmDialog中单击“确定”按钮后,我无法下载zip文件。如果我没有使用confirmDialog,则可以下载文件。谁能帮我这个忙,
在这里,我添加了代码以供参考。
<h:form>
<p:panelGrid rendered="true">
<p:commandButton style="HEIGHT: 24px; WIDTH: 300px" id="AjaxFalse"
value="AjaxFalse"
action="#{testDownload.getZipFile}"
title="AjaxFalse" rendered="true">
<p:confirm message="Are you sure?"
header="Confirmation"
icon="ui-icon-alert" />
</p:commandButton>
</p:panelGrid>
<p:confirmDialog global="true" showEffect="fade" hideEffect="fade" width="500">
<h:panelGroup layout="block" style="text-align: center">
<p:commandButton value="Ok" type="submit" styleClass="ui-confirmdialog-yes" style="width:70px;"/>
<p:commandButton value="Cancel" type="button" styleClass="ui-confirmdialog-no" style="width:70px;"/>
</h:panelGroup>
</p:confirmDialog>
</h:form>
Run Code Online (Sandbox Code Playgroud)
我的菜豆是
public class TestDownload
{
//some code here
//Downloading the zip file in jsf2.x
public String getZipFile()
{
try{
//enter code here
FacesContext fc = FacesContext.getCurrentInstance();
ExternalContext ec = fc.getExternalContext();
ec.setResponseHeader("Content-Disposition", "attachment;filename=\"" + Test + ".zip\"");
ec.setResponseCharacterEncoding("UTF-8");
ec.setResponseContentType("application/zip");
//This method will generate the required file.
new BulkloadImporter().generateIntegrationXSDs(getId(), ec.getResponseOutputStream());
fc.responseComplete();
return "Save";
}
catch(Exception e)
{
//Handling exception
}
}
//some code here
}
Run Code Online (Sandbox Code Playgroud)
此问题与“下载”无关。到目前为止(PrimeFaces 5.3 / 5.3.2)结合使用<p:confirm...>全局对话框ajax="false" 不起作用。通常不会调用服务器端操作。
有两种可能的解决方案:
可以在PrimeFaces文档中找到非全局用法的示例(适用于这种情况):
ConfirmDialog入门 ConfirmDialog有两种模式:全局和非全局。非全局模式与用于简单客户端api show()和hide()的对话框组件几乎相同。
Run Code Online (Sandbox Code Playgroud)<h:form> <p:commandButton type="button" onclick="PF('cd').show()" /> <p:confirmDialog message="Are you sure about downloading this file?" header="Initiating download" severity="alert" widgetVar="cd"> <p:commandButton value="Yes Sure" action="#{testDownload.getZipFile}" ajax="false" update="messages" oncomplete="PF('cd').hide()"/> <p:commandButton value="Not Yet" onclick="PF('cd').hide();" type="button" /> </p:confirmDialog> </h:form>
| 归档时间: |
|
| 查看次数: |
616 次 |
| 最近记录: |