概述
本文主要描述在Oracle ADF中使用Popup,利用showPopupBehavior,popup与dialog可以方便地实现。
需求1、
由按钮触发弹出Popup2、第一个Popup中提示是否确定(Confirmation),如果确定,则进而弹出提示操作成功的Popup(Tip)
实现
1.创建ADF应用
2、在ViewController项目中创建名为main.jspx的新页面,在该页面中添加Button
3、在main.jspx页面中添加popup,并在popup中嵌入dialog,由于该popup的作用是提示用户进行操作确认,因此在Title中填如“Confirmation”,Type类型选择为“okCancel”
4、在该Dialog中添加OutputText,提示用户确认
5、为该Dialog添加dialogListener,根据用户点击不同的按钮(ok or cancel)以触发不同的事件
6、在该dialogListener()方法中添加如下代码:
public void dialogListener(DialogEvent dialogEvent) {
if (dialogEvent.getOutcome() == DialogEvent.Outcome.ok) {
FacesContext facesContext = FacesContext.getCurrentInstance();
ExtendedRenderKitService extendedRenderKitService =
Service.getRenderKitService(facesContext,
ExtendedRenderKitService.class);
String script =
"var popup;popup = AdfPage.PAGE.findComponent('" + "p2" + "');popup.show();";
extendedRenderKitService.addScript(facesContext, script);
} else if (dialogEvent.getOutcome() == DialogEvent.Outcome.cancel) {
//Nothing to do here...
}
}
7、完成了逻辑添加之后,继续在main.jspx页面中添加popup,以提示操作成功。这里Title为“Tip”,Type为“ok”
8、在步骤2中创建出的Button中添加showPopupBehavior组件,设置其popupId为第一个添加的popup的id,即p1
9、全部布局完成之后的页面Structure应为:
10、保存应用,运行并查看结果
页面运行:
点击该Button:
点击OK: