Skip to main content

{"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

KR said…
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.
MarioK said…
Very useful post.
Is there a way to close popup programmatically? Thanks
Srini Alavala said…
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
Tree Strepek said…
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

Popular posts from this blog

How to set Bind Variable Values at runtime ?

In this post I'm sharing a couple of approaches for programmatically setting bind variables values at run time. This post is an attempt to explain 'When to use what ?'[ In case if you are familiar with 'Bind Variables' in ADF BC, please refer Section 5.10, Working with Bind Variables in Fusion Developer's Guide ]

1. Set the Bind Variable value using RowSet::setNamedWhereClauseParam(...)

You can use use the setNamedWhereClauseParam(...) method on the ViewObject interface (which extends oracle.jbo.RowSet) to set the value for bind variables. Please note this sets the value on default RowSet. In other words, this doesn't have any effect on the secondary RowSets that you/system generates.
ViewObject vo = am.findViewObject("EmployeesView1"); vo.setNamedWhereClauseParam("bindVarDeptId", new Number(10)); vo.executeQuery();
2. Set the Bind Variable value using ViewObject's VariableValueManager::setVariableValue(...)

VariableValueManager Ma…