所以这就是事情。我有一个带按钮的弹出窗口,按钮本身有一个fileDownloadActionListener,这个按钮负责下载一个excel文件。所以我需要的是在生成文件后立即隐藏弹出窗口。
这是我的.jspx文件(只是弹出窗口)
<af:popup childCreation="deferred" autoCancel="enabled"
id="myPopUp"
contentDelivery="lazyUncached"
binding="#{viewScope.mbMyBean.myPopUp}"
partialTriggers="b17">
<af:dialog id="d16" type="cancel"
title="Do you wish to download a file?"
inlineStyle="width:400px;">
<af:panelGroupLayout id="pgl32"
inlineStyle="max-width: 200px;">
<af:outputText value="You're about to download a file. Ready?" id="ot45"
/>
</af:panelGroupLayout>
<f:facet name="buttonBar">
<af:button text="GO" id="b17"
<af:fileDownloadActionListener contentType="excelHTML"
filename="#{viewScope.mbMyBean.FileName}"
method="#{viewScope.mbMyBean.GenerateEmptyExcel}"
/>
</af:button>
</f:facet>
</af:dialog>
</af:popup>
这是java方法:
public void GenerateEmptyExcel(FacesContext facesContext, OutputStream outputStream) {
try {
HSSFWorkbook wb1 = generateEmptyExcelFile();
wb1.write(outputStream);
outputStream.flush();
outputStream.close();
this.myPopUp.hide();
AdfFacesContext.getCurrentInstance().addPartialTarget(this.myPopUp);
System.gc();
} catch (Exception e) {
e.printStackTrace();
}
}
问题
弹出窗口不会隐藏。
备注
答案 0 :(得分:1)
理想情况下this.myPopUp.hide();
应关闭弹出窗口,但如果由于某种原因它无法正常工作,您可以尝试使用javascript关闭弹出窗口:
public static void hidePopup(String popupId){
if (popupId != null)
{
ExtendedRenderKitService service =
Service.getRenderKitService(FacesContext.getCurrentInstance(),
ExtendedRenderKitService.class);
StringBuffer hidePopup = new StringBuffer();
hidePopup.append("var popupObj=AdfPage.PAGE.findComponent('" + popupId +
"'); popupObj.hide();");
service.addScript(FacesContext.getCurrentInstance(), hidePopup.toString());
}
}
您可以使用以下内容获取可以传递给hidePopup的弹出窗口clientId:this.myPopUp.getClientId(FacesContext.getCurrentInstance());
答案 1 :(得分:1)
下载文件后遇到同样的问题,你应该试试这个:
使用资源类型javascript触发commandButton中的事件单击
<af:resource type="javascript">
function customHandler(evt) {
console.log(evt);
var exportCmd = AdfPage.PAGE.findComponentByAbsoluteId("pt1:b17");
console.log(exportCmd);
var actionEvent = new AdfActionEvent(exportCmd);
console.log(actionEvent);
actionEvent.forceFullSubmit();
actionEvent.noResponseExpected();
actionEvent.queue(false);
setTimeout(function(){hidePopup();}, 1000);
}
function hidePopup() {
var popup = AdfPage.PAGE.findComponent("pt1:popupAceptarDescargarPlantilla::content");
popup.hide();
}
</af:resource>
您应该有以下按钮:
<af:commandButton text="Aceptar" id="b17" visible="false" clientComponent="true" partialSubmit="true">
<af:fileDownloadActionListener contentType="excelHTML" filename="#{viewScope.mbGestionArchivos.nombre_archivo}" method="#{viewScope.mbGestionArchivos.generateExcelVacio}"/>
</af:commandButton>
<af:button text="Aceptar" id="botonPrueba" actionListener="#{viewScope.mbInformeDetalle.prepareForDownloadAction}" clientComponent="true" partialSubmit="true"></af:button>
这是按钮调用的java方法:
public void prepareForDownloadAction(ActionEvent act) {
FacesContext context = FacesContext.getCurrentInstance();
ExtendedRenderKitService erks =
Service.getService(context.getRenderKit(),
ExtendedRenderKitService.class);
erks.addScript(context, "customHandler();");
}
隐藏按钮是使用javascript ADF方法触发的,神奇发生在setTimeout中,当执行此函数时,我们避免一秒钟进行提交但是请求转到服务器,这里我们可以观察文件是如何启动的