浏览器事件关闭在ADF中

时间:2018-05-31 08:51:51

标签: javascript java jsf oracle-adf

我有JSF页面我希望在用户尝试关闭时检测浏览器事件

Tab或所有浏览器阻止他,如果他想离开此页面或留下     我需要在后端通过调用java方法 java脚本     我尝试这样做但是页面上的服务器监听器看不到来自js的动作     所以我需要帮助才能取得这样的成功

window.onbeforeunload = function (event) {
    console.log(" Test Event Console .")
    var docComponent = AdfPage.PAGE.findComponentByAbsoluteId('d1');

    console.log(" value component = " + docComponent);

    var dialogText = ' browser Is Closed  !.. ';
    console.log(dialogText);

   var x = AdfCustomEvent.queue(docComponent, "test",{"test":"so"},false);
   console.log("test " + x);
    var y = 0;


    event.returnValue = dialogText;

    return x;
};


<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE html>
<f:view xmlns:f="http://java.sun.com/jsf/core" xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
     <af:document title="testBrowserChrome.jsf" id="d1" clientComponent="true"  onunload="onbeforeunload">
      <af:form id="f1">
          <af:resource type="javascript" source="resources/js/BrowserEventClose.js"/>
          <af:serverListener type="test" method="#{viewScope.ServerTest.testServerListener}"/>
    </af:form>
    </af:document>

</f:view>

1 个答案:

答案 0 :(得分:0)

我建议您创建一个具有该操作的按钮,并使用以下代码模仿按钮触发器,因为 theButton 是该按钮的ID。

var adfButton = AdfPage.PAGE.findComponentByAbsoluteId("theButton");
AdfActionEvent.queue(adfButton , true /*Immediate*/); 
相关问题