We've recently received a few inquiries about how to display a web link in a MAF app that will open in the device’s browser app when the user taps on it.
It seems that some teams have been relying on a side effect of whitelisting to circumvent the default MAF behaviour, which is to display the contents of the web link directly in the current WebView. In earlier releases of MAF, if you did not add the web link’s URL to the whitelist, it would be opened in the device’s browser app instead. However, with recent changes to Cordova and MAF whitelist functionality, this is no longer the case.
This was never really the correct way to do it anyway, so what is the correct way?
InAppBrowser plugin
The Apache Cordova team has kindly provided a plugin called cordova-plugin-inappbrowser that gives you complete control over how the web link should be displayed.
How do I use this in my MAF app?
First, you need to add the plugin to your MAF app as follows:
1.
Download the plugin from
GitHub2.Extract the contents of the downloaded zip file into your MAF app’s source code (preferably in the top-level src folder)
3.Add the plugin to your MAF app’s maf-application.xml file via the Plugins UI in JDeveloper
Next, add a link to your page that invokes a custom JavaScript function as follows:
1.Drag a Link (<amx:commandLink>) onto your page
2.Edit the Action Listener property of this link by creating a new Managed Bean with a single method
3.
Modify the newly created bean’s method to invoke a custom JavaScript function as follows:
AdfmfContainerUtilities.invokeContainerJavaScriptFunction(
AdfmfJavaUtilities.getFeatureId(), "displayLink", new Object[] { });
Finally, create the custom JavaScript file and add it to your app, as follows:
1. Create a new JavaScript file within the feature into which you’ve added the link
2. Modify this JavaScript file to include the referenced function as follows (specifying your desired URL):
(function () {
displayLink = function() {
cordova.InAppBrowser.open('http://www.oracle.com', '_system');
}
}) ();
3. Add the newly created JavaScript file to your feature’s content via the maf-feature.xml file.
The
MAF Developer Guide provides detailed information about how to complete each of the steps listed above.
Having completed these steps, deploy to a device or simulator/emulator for testing.
Conclusion
Do not use whitelisting in an attempt to force your MAF app to display an external web link in the device's browser app.
Whitelisting should only be used to secure references to external web links that are displayed within the current WebView of your MAF app.
Use the cordova-plugin-inappbrowser plugin supplied by the Apache Cordova team to control the display of external web links from your MAF app.