我遇到使用clientListener处理disclosureEvent的问题。每当用户离开panelTabbed中的选项卡时,我都会尝试显示“确认/取消”弹出窗口。
下面是代码:(这是Oracle ADF代码角上提供的完全相同的代码)
<af:resource type="javascript">
function alertTabSwitch(disclosureEvent){
var tab = disclosureEvent.getSource();
if(tab.getDisclosed()==false){
var popup = tab.findComponent('p1');
popup.show();
popup.setProperty("tabToOpen",tab.
disclosureEvent.cancel();
}
}
function handlePopupOkCancel(actionEvent){
var popupButton = actionEvent.getSource();
var butPressed = popupButton.getProperty('popupAction');
var dialog = popupButton.getParent();
var popup = dialog.getParent();
if(butPressed == 'OK'){
var tabToFindAndFocusOnString = popup.getProperty("tabToOpen");
if(tabToFindAndFocusOnString.length > 0){
var tab = AdfPage.PAGE.findComponentByAbsoluteId(tabToFindAndFocusOnString);
tab.setDisclosed(true);
actionEvent.cancel();
popup.hide();
}
}
else{
//close popup and stay on page
actionEvent.cancel();
popup.hide();
}
}
</af:resource>
<af:panelStretchLayout id="psl1">
<f:facet name="center">
<af:panelTabbed id="pt1">
<af:showDetailItem text="TAB 1" id="sdi1" disclosed="true" stretchChildren="first"
clientComponent="false">
First Tab
<af:clientListener method="alertTabSwitch" type="disclosure"/>
</af:showDetailItem>
<af:showDetailItem text="TAB 2" id="sdi2" stretchChildren="first" clientComponent="false">
Second Tab
<af:clientListener method="alertTabSwitch" type="disclosure"/>
</af:showDetailItem>
</af:panelTabbed>
<!-- id="af_one_column_stretched" -->
</f:facet>
<f:facet name="start">
<af:popup childCreation="deferred" autoCancel="disabled" id="p1" clientComponent="true"
contentDelivery="immediate">
<af:dialog id="d1" title="Tab Switch Alert" type="none">
<f:facet name="buttonBar">
<af:panelGroupLayout id="g1">
<af:commandButton text="OK" id="cb1" partialSubmit="true">
<af:clientAttribute name="popupAction" value="OK"/>
<af:clientListener method="handlePopupOkCancel" type="action"/>
</af:commandButton>
<af:commandButton text="CANCEL" id="cb2" partialSubmit="true">
<af:clientAttribute name="popupAction" value="CANCEL"/>
<af:clientListener method="handlePopupOkCancel" type="action"/>
</af:commandButton>
</af:panelGroupLayout>
</f:facet>
<af:outputText value="Do you really want to switch tabs?" id="ot1"
inlineStyle="font-size:medium; color:Red;"/>
</af:dialog>
<af:clientAttribute name="tabToOpen" value=""/>
</af:popup>
</f:facet>
</af:panelStretchLayout>
一切都在客户端完成。当我单击选项卡时,首先会针对所选选项卡触发“取消选择”事件,并且该选项卡的公开值将更改为false。更改值后,将调用侦听器。 所以在javascript中,单击OK按钮后再次显示相同的选项卡。 如果在调用af:clientListener之前没有更改该值,则不会发生此问题。
有人可以帮我吗?
我在这里更彻底地描述了这个问题。 https://forums.oracle.com/message/11227277#11227277
此致 Navaneet
答案 0 :(得分:1)
将标记更改为以下内容并且它将起作用,这是针对11.1.1.7
进行测试的<af:resource type="javascript">
var theTabToClose;
var theTabToOpen;
function alertTabSwitch(disclosureEvent){
var tab = disclosureEvent.getSource(); //This is the tab to close
if(tab.getDisclosed()==false){
theTabToClose = tab;
theTabToOpen = disclosureEvent.getDisclosureCounterpart();
var popup = tab.findComponent('p1');
disclosureEvent.cancel();
popup.show();
}
}
function handlePopupOkCancel(actionEvent){
var popupButton = actionEvent.getSource();
var butPressed = popupButton.getProperty('popupAction');
var dialog = popupButton.getParent();
var popup = dialog.getParent();
if(butPressed == 'OK'){
theTabToOpen.setDisclosed(true);
}else{
theTabToClose.setDisclosed(true);
}
actionEvent.cancel();
popup.hide();
}
</af:resource>