{"ADFMobile": Programatically invoking a popup in ADF Mobile}

Well, as you rightly guessed, in this post I'm talking about ADF mobile ;). My first 'creative' post on this technology. Straight to the topic:
There is no Java API to queue an event on actionable component in ADF mobile as of now. Recently I noticed a work around solution using  both Java and JavaScript for the same(Thanks to Piyush Hari and Matt Cooper). This involves some amount of code,but it is fun.

The following code snippet(Java + JavaScript) simulates button action event programatically.
The below method is Java bean method bound to a button. Note that this is just simple example to demo the idea. In real scenario it could be your business logic which might get triggered in response to various other user actions on your page and may involve complex logic too.

public void somePOJOMethod(...) {

//Business logic go here
//Now based on some condition 
//invoke popup by simulating 
//button action
 AdfmfContainerUtilities.
 invokeContainerJavaScriptFunction
   ("feature1",
    "showPopup",
     new Object[] {} );
}

The above code snippet calls  showPopup() JavaScript method to generate action event programtaically. See the following doc to learn more about  method AdfmfContainerUtilities.invokeContainerJavaScriptFunction. The definition of showPopup() JavaScript method is given below. As stated a while ago, this method generates the button action event programatically. The button used in this example has amx:showPopupBehavior added to display a popup and apparently the generated event ends up in displaying the popup.


(function () {
    showPopup = function () {
       
        var element = document.getElementById("cb4");
        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);
    };

})();

Download

You can download the sample workspace from here.
[ Runs with Oracle JDeveloper 11.1.2.4.0 with mobile extension added.]

Comments

  1. Good post! Could u do a blog post on Autosuggest behaviour in ADF mobile, since ADF mobile does not have autosuggest tag/client listener components.

    ReplyDelete
  2. Very useful post.
    Is there a way to close popup programmatically? Thanks

    ReplyDelete
  3. Very useful info. Thank you very much.

    How do we close the popup? We would like to close the popup with an action from the popup.

    Thanks!
    Srini

    ReplyDelete
  4. Thanks for this post. It is very good. Here's a question. Say I want to capture the users response-> how do I do that part? Expected results would be user clicked "ok" or "cancel".

    I would greatly appreciate that information.
    Theresa

    ReplyDelete

Post a Comment