Search code examples
javajavascriptoracle-adforacle-adf-mobile

How to close Popup Behavior within time interval in ADF Mobile?


I am closing my popup using closePopupBehavior. How can I close my popup within 5 seconds after invoking the popup.

Below is my amx page

<amx:view xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:amx="http://xmlns.oracle.com/adf/mf/amx"
      xmlns:dvtm="http://xmlns.oracle.com/adf/mf/amx/dvt">
<amx:panelPage id="pp1">
<amx:facet name="header">
  <amx:outputText value="Header" id="ot1"/>
</amx:facet>
<amx:facet name="primary">
  <amx:commandButton id="cb1"/>
</amx:facet>
<amx:facet name="secondary">
  <amx:commandButton id="cb2"/>
</amx:facet>
 <amx:commandButton text="Show popup - using Java" id="cb3" actionListener="#{test.btnClick}">
 <amx:showPopupBehavior id="spb1" popupId="p1" align="after" alignId="cb3"/>  </amx:commandButton>
 </amx:panelPage>
 <amx:popup id="p1">
    <amx:panelGroupLayout id="pgl2" layout="vertical">
        <amx:outputText value="I am called from java." id="ot2"/>
    </amx:panelGroupLayout>
    <amx:commandButton text="Close" id="cb5">
        <amx:closePopupBehavior id="cpb1" popupId="p1" type="action"/>
    </amx:commandButton>
 </amx:popup>
 </amx:view>

Below is my Managed Bean

public class TestBean{
    public void btnClick(ActionEvent actionEvent) {

    AdfmfContainerUtilities.invokeContainerJavaScriptFunction("feature1",
                                                                     "showPopup",
                                                                      new Object[] {} );
}
}

If it is possible to close by using javascript also post your answer.Thank you very much


Solution

  • I see you are using the example mentioned here http://www.jobinesh.com/2013/12/adfmobile-programatically-invoking.html by Jobinesh.

    In order to close the popup after let's say 5 seconds you need to add the below function in you JS file

    (function () {
        hidePopup = function () {
    
            var element = document.getElementById("cb5");
            customTriggerEvent(element, "touchstart");
            customTriggerEvent(element, "touchend");
        }
    
        var customTriggerEvent = function (eventTarget, eventType, triggerExtra) {
            var evt = document.createEvent("HTMLEvents");
            evt.initEvent(eventType, true, true);
            evt.view = window;
            evt.altKey = false;
            evt.ctrlKey = false;
            evt.shiftKey = false;
            evt.metaKey = false;
            evt.keyCode = 0;
            evt.charCode = 'a';
            if (triggerExtra != null)
                evt.triggerExtra = triggerExtra;
            eventTarget.dispatchEvent(evt);
        };
    
    })();
    

    where "cb5" is the id of a button with closePopupBehavior and at the end of your showPopup JS function you need to add below line

    setTimeout(function(){hidePopup();}, 5000);