This chapter describes the ADF Mobile JavaScript API extensions, the ADF Mobile Container Utilities API, and how to use the adfmfjavaUtilities
API for custom springboard applications.
This chapter includes the following sections:
Section 6.1, "Using ADF Mobile APIs to Create a Custom Springboard Application Feature"
Section 6.3, "Accessing Files Using the getDirectoryPathRoot Method"
Using JavaScript to call the JavaScript API extensions enables you to add the navigation functions to a custom springboard authored in HTML. As stated in Section 5.4.4, "What You May Need to Know About Custom Springboard Application Features with HTML Content," you can enable callbacks and leverage PhoneGap by including methods in the JavaScript
<script>
tag. Example 6-1 illustrates using this tag to call PhoneGap.
Example 6-1 Embedding the <script> Tag in an HTML Springboard Page
... <script type="text/javascript" charset="utf-8" src=../../../www/js/phonegap-1.0.0.js"></script> <script type="text/javascript" src="../../../www/js/adf.el.js"></script> ...
Note:
You can use any of the JavaScript methods located in adf.el.js
that begin with adf.mf.api
. For information on usage, see Section 6.2, "The ADF Mobile Container Utilities API."
ADF Mobile's use of JavaScript leverages PhoneGap's infrastructure to initialize the browser's DOM (Document Object Model) with the appropriate JavaScript constructors. It also avoids race conditions by using the PhoneGap object constructor infrastructure. ADF Mobile also posts PhoneGap messages to the native device code to initiate the ADF Mobile PhoneGap commands.
The ADF Mobile extension to the PhoneGap API enables the mobile device's API to access the configuration set in the adfmf-feature.xml
and adfmf-application.xml
files, which in turn results in communication between the mobile device and ADF Mobile's infrastructure. These extensions also direct the display behavior of the application features.
The methods of the ADF Mobile Container Utilities API provide ADF Mobile applications with such functionality as displaying or hiding the navigation bar, displaying a springboard, or invoking application features. You can use these methods at the Java and JavaScript layers of ADF Mobile.
In JavaScript, the Container Utilities API is located on the adf.mf.api
JavaScript object, as shown in Example 6-2, which illustrates calling the
gotoSpringboard
method.
Example 6-2 Calling the Container Utilities API in JavaScript
<script type="text/javascript" charset="utf-8" src="../../../www/js/phonegap-1.0.0.js"></script> ... adf.mf.api.gotoSpringboard(); ...
Note:
The relative path to the location of the www/js
directory always reflects the location of the HTML springboard page, which can be located at the root of the view controller's public_html
directory, or within a subdirectory of it. In Example 6-2, the path defined by the
src
attribute (../../../www/js/phonegap-1.0.0.js
) is relative to the location of the HTML springboard file when it is located at the root of the public_html
directory, as follows:
JDeveloper\mywork\Mobile_Application\ViewController\public_html\customspringboard.html
To enable the springboard files located within the subdirectories of public_html
to access the hosted JavaScript files, you must adjust the relative path definition accordingly by adding ../
for each subdirectory location.
Because the path does not exist during design time, JDeveloper notes the JavaScript Includes in the source editor as an error by highlighting it with a red, wavy underline. This path is resolved at runtime.
In Java, the Container Utilities API is implemented as static methods on the AdfmfContainerUtilities
class, which is located in the oracle.adfmf.framework.api
package. Example 6-3 illustrates calling the
gotoSpringboard
method. For more information on oracle.adfmf.framework.api.AdfmfContainerUtilities
, see Oracle Fusion Middleware Java API Reference for Oracle ADF Mobile.
Example 6-3 Calling the Container Utilities API in Java
import oracle.adfmf.framework.api.AdfmfContainerUtilities; ... AdfmfContainerUtilities.gotoSpringboard(); ...
The signatures of Java and JavaScript both match. In Java, they are synchronous and return results directly. Because JavaScript is asynchronous, there are two callback functions added for every function: a success
callback that returns the results and a failed
callback that returns any exception that is thrown. Within a Java method, the success
value is returned from the function or method and the exception is thrown directly from the method. For example, a call with no arguments, such as public static (, , ...) throws
is executed within Java as follows:
try { result = AdfmfContainerUtilities.(, , ...); } catch() { ... }
Because JavaScript calls are asynchronous, the return is required through the callback mechanism on the completion of the execution of the function. The signature for the JavaScript is adf.mf.api.(, , ..., , )
and is invoked as follows:
adf.mf.api.(, , ..., , )
This call is defined as function(request, response)
. The value of the request
argument is the actual request. The response
is defined as function(request, response)
and its value is the actual request. The response is thrown during the execution of the function.
A call with one or more arguments, such as public static <return value> <function name>(<arg0>, <arg1>, ...) throws <exceptions>
, is executed within Java as follows:
try { result = AdfmfContainerUtilities.<function_name>(<arg0>, <arg1>, ...); } catch(<exception>) { ... }
JavaScript calls cannot return a result because they are asynchronous. They instead require a callback mechanism when the execution of the function has completed. The signature for both the success and failed callbacks is function(request, response)
, where the request
argument is a JSON representation for the actual request and the response
is the JSON representation of what was returned by the method (in the case of success
callback functions) or, for failed
callback functions, a JSON representation of the thrown exception.
The Container Utilities API provides the following methods:
checkforNewConfiguration—Checks for the changes in a hosted
connections.xml
file.
getApplicationInformation—Retrieves the metadata for the ADF Mobile application.
gotoDefaultFeature—Displays the default application feature.
getFeatures—Retrieves the application features.
gotoFeature—Displays a specific application feature.
getFeatureByName—Retrieves information about the application feature using the application feature's name.
getFeatureById—Retrieves an application feature using its ID.
resetFeature—Resets the application feature to the same state as when it was loaded.
gotoSpringboard—Displays the springboard.
hideNavigationBar—Hides the navigation bar.
showNavigationBar—Displays the navigation bar.
"invokeMethod"—Invokes a Java method.
invokeContainerJavaScriptFunction—Invokes a JavaScript method.
When the Configuration Service is used, this method requests that ADF Mobile check a server that hosts the connections.xml
file for any changes to the configured endpoints. To check for changes, ADF Mobile creates a thread that compares the connection-related content hosted on the server to the configuration on the device. If ADF Mobile finds that the device configuration is outdated, then the checkforNewConfiguration
method issues a non-blocking call that notifies the user that a new configuration has been detected and then closes the application. ADF Mobile reminds the user to restart the application.
In Java, the method is as follows:
public static void checkForNewConfiguration() throws oracle.adfmf.framework.exception.AdfException
Example 6-4 illustrates using this method.
Example 6-4 Retrieving Configuration Information Using Java
import oracle.adfmf.framework.api.AdfmfContainerUtilties; ... try { AdfmfContainerUtilities.checkForNewConfiguration(); }catch(AdfException e) { // handle the exception }
In JavaScript, the success
and failed
callback functions enable the returned value and the exception to be passed back to the JavaScript calling code as follows:
public void checkForNewConfiguration(success, failed)
The success
callback must be in the form of function(request, response)
, where the request
argument contains the original request and the response
argument contains the associated AdfmfContainerUtilities
method's return value (void
). The failed
callback must be in the form of function(request, response)
where the request
argument contains the original request and the response
argument contains the error (AdfException
).
Example 6-5 illustrates using these callback functions to retrieve the configuration information.
This method returns an ApplicationInformation
object that contains information about the application. This method returns such metadata as the application ID, application name, version, and the vendor of a custom springboard application.
Within Java, this method is called as follows:
public static oracle.adfmf.framework.ApplicationInformation getApplicationInformation() throws oracle.adfmf.framework.exception.AdfException
Example 6-6 illustrates calling this method.
Example 6-6 Retrieving Application Information Using Java
import oracle.adfmf.framework.api.AdfmfContainerUtilties; ... try { ApplicationInformation[] ai = AdfmfContainerUtilities.getApplicationInformation(); ... }catch(AdfException e) { // handle the exception }
In JavaScript, the success
and failed
callback functions enable the returned value and the exception to be passed back to the JavaScript calling code as follows:
public void getApplicationInformation(success, failed)
The success
callback must be in the form of function(request, response)
, where the request
argument contains the original request and the response
argument contains the associated AdfmfContainerUtilities
method's return value, which is the ApplicatiaonInformation
object containing application-level metadata. This includes application name, vendor, version, and application ID.
The failed
callback must be in the form of function(request, response)
, where the request contains the original request and the response contains the error.
Example 6-7 illustrates using these callback functions to retrieve the application information.
This method requests that ADF Mobile display the default application feature. The default application feature is the one that is displayed when the ADF Mobile application is started.
Note:
This method may not be able to display an application feature if it has authentication- or authorization-related problems.
In JavaScript, the success
and failed
callback functions enable the returned value and the exception to be passed back to the JavaScript calling code as follows:
public void gotoDefaultFeature(success, failed)
The success
callback function must be in the form of function(request, response)
, where the request
argument contains the original request and the response
argument contains the associated AdfmfContainerUtilities
method's return value (void
).
The failed
callback function must be in the form of function(request, response)
, where the request
argument contains the original request and the response
argument contains the error.
Example 6-8 illustrates using these callbacks to call the default application feature.
This method returns an array of FeatureInformation
objects that represent the available application features. The returned metadata includes the feature ID, the application feature name, and the file locations for the image files used for the application icons. This call enables a custom springboard implementation to access the list of application features that are available after constraints have been applied. (These application features would also display within the default springboard.)
Within Java, this method is called as follows:
public static oracle.adfmf.framework.FeatureInformation[] getFeatures() throws oracle.adfmf.framework.exception.AdfException
Example 6-9 illustrates using this method.
Example 6-9 Retrieving the Application Feature Information Using Java
import oracle.adfmf.framework.api.AdfmfContainerUtilties; ... try { FeatureInformation[] fia = null; fia = AdfmfContainerUtilities.getFeatures(); for(int f = 0; f < fia.length; ++f) { FeatureInformation fi = fia[i]; ... } }catch(AdfException e) { // handle the exception }
In JavaScript, the success
and failed
callback functions enable the returned values and the exceptions to be passed back to the JavaScript calling code as follows:
public void getFeatures(success, failed)
The success
callback function must be in the form of function(request, response)
, where the request
argument contains the original request and the response
argument contains the associated AdfmfContainerUtilities
method's return value (the array of FeatureInformation
objects).
The failed
callback function must be in the form of function(request, response)
, where the request
argument contains the original request and the response
argument contains the error (AdfException
).
This method requests that ADF Mobile display the application feature identified by its ID.
Note:
This method may not be able to display an application feature if it has authentication- or authorization-related problems.
Within Java, this method is called as follows:
public static void gotoFeature(java.lang.String featureId) throws oracle.adfmf.framework.exception.AdfException
This method's parameter, as shown in Example 6-11, is the ID of the application feature.
Example 6-11 Activating an Application Feature
import oracle.adfmf.framework.api.AdfmfContainerUtilties; ... try { AdfmfContainerUtilities.gotoFeature("feature.id"); }catch(AdfException e) { // handle the exception }
In JavaScript, the success
and failed
callback functions enable the returned value and the exception to be passed back to the JavaScript calling code as follows:
public void gotoFeature(featureId, success, failed)
The featureId
parameter is the application feature ID. This parameter activates the success
callback function and must be in the form of function(request, response)
, where the request contains the original request and the response contains the associated AdfmfContainerUtilities
method's return value (void
).
The failed
callback function must be in the form of function(request, response)
, where the request contains the original request and the response contains the error.
Example 6-12 illustrates using these callback functions to call an application feature.
This method returns information about the application feature using the passed-in name of the application feature.
Within Java, this method is called as follows:
public static oracle.adfmf.framework.FeatureInformation getFeatureByName(java.lang.String featureName) throws oracle.adfmf.framework.exception.AdfException
This method's parameter, as shown in Example 6-13, is the name of the application feature.
Example 6-13 Retrieving the Application Feature Information Using the Application Feature Name
... try { FeatureInformation fi = AdfmfContainerUtilities.getFeatureByName("feature.name"); }catch(AdfException e) { // handle the exception }
In JavaScript, the success
and failed
callback functions enable the returned value and the exception to be passed back to the JavaScript calling code as follows:
public void getFeatureByName(featureName, success, failed)
The featureName
parameter is the name of the application feature. The success
callback function and must be in the form of function(request, response)
, where the request contains the original request and the response contains the associated AdfmfContainerUtilities
method's return value (void
).
The failed
callback function must be in the form of function(request, response)
, where the request contains the original request and the response contains the error.
Example 6-14 illustrates using these callback functions.
Example 6-14 Using JavaScript Callback Functions to Retrieve the Application Feature Information Using the Application Feature Name
adf.mf.api.getFeatureByName("feature.name", function(req, res) { alert("getFeatureByName complete"); }, function(req, res) { alert("getFeatureByName failed with " + adf.mf.util.stringify(res); } );
This method retrieves an application feature using its application ID.
Within Java, this method is called as follows:
import oracle.adfmf.framework.api.AdfmfContainerUtilties;
This method's parameter, as shown in Example 6-15, is the ID of the application feature.
Example 6-15 Retrieving an Application Feature Using its ID in Java
try { FeatureInformation fi =AdfmfContainerUtilities.getFeatureById("feature.id"); }catch(AdfException e) { // handle the exception }
In JavaScript, the success
and failed
callback functions enable the returned value and the exception to be passed back to the JavaScript calling code as follows:
public void getFeatureById(featureId, success, failed)
The featureId
parameter is the ID of the application feature. The success
callback function and must be in the form of function(request, response)
, where the request contains the original request and the response contains the associated AdfmfContainerUtilities
method's return value (void
).
The failed
callback function must be in the form of function(request, response)
, where the request contains the original request and the response contains the error.
Example 6-16 illustrates using these callback functions to retrieve an application feature.
This method resets the state of the application feature. It resets the Java-side model for the application feature and then restarts the user interface presentation as if the ADF Mobile application had just been loaded and displayed the application feature for the first time.
Within Java, this method is called as follows:
public static void resetFeature(java.lang.String featureId) throws oracle.adfmf.framework.exception.AdfException
The method's parameter, as shown in Example 6-17, is the ID of the application feature that is to be reset.
Example 6-17 Resetting an Application Feature in Java
import oracle.adfmf.framework.api.AdfmfContainerUtilties; ... try { AdfmfContainerUtilities.resetFeature("feature.id"); }catch(AdfException e) { // handle the exception
In JavaScript, the success
and failed
callback functions enable the returned value and exception to be passed back to the JavaScript calling code as follows:
public void resetFeature(featureId, success, failed)
The success
callback function and must be in the form of function(request, response)
, where the request contains the original request and the response contains the associated method's return value (The ID of the application feature).
The failed
callback function must be in the form of function(request, response)
, where the request contains the original request and the response contains the error.
Example 6-18 illustrates using these callback functions to call an application feature.
This method requests that ADF Mobile display the springboard.
Note:
This method may not be able to display the springboard if it has not been designated as a feature reference in the adfmf-application.xml
file, or if it has authentication or authorization-related problems. See also Section 5.4, "Configuring the Springboard and Navigation Bar Behavior."
Within Java, this method is called as follows:
public static void gotoSpringboard()
Example 6-19 illustrates using this method
Example 6-19 Activating the Springboard in Java
import oracle.adfmf.framework.api.AdfmfContainerUtilties; ... try { AdfmfContainerUtilities.gotoSpringboard(); }catch(AdfException e) { // handle the exception }
In JavaScript, the success
and failed
callback functions enable the returned value and the exception to be passed back to the JavaScript calling code as follows:
public void gotoSpringboard(success, failed)
The success
callback function must be in the form of function(request, response)
, where the request contains the original request and the response contains the associated method's return value (void
).
The failed
callback function must be in the form of function(request, response)
, where the request contains the original request and the response contains the error.
Example 6-20 illustrates using these callback functions.
This method requests that ADF Mobile hide the navigation bar.
Within Java, this method is called as follows:
public static void hideNavigationBar()
Example 6-21 illustrates using this method.
Example 6-21 Hiding the Navigation Bar in Java
import oracle.adfmf.framework.api.AdfmfContainerUtilties; ... try { AdfmfContainerUtilities.hideNavigationBar(); }catch(Exception e) { // handle the exception }
In JavaScript, the success
and failed
callback functions enable the returned value and the exception to be passed back to the JavaScript calling code as follows:
public void hideNavigationBar(success, failed)
The success
callback function must be in the form of function(request, response)
, where the request contains the original request and the response contains the associated method's return value (void
).
The failed
callback function must be in the form of function(request, response)
, where the request contains the original request and the response contains the error.
Example 6-22 illustrates using these callback functions.
This method requests that ADF Mobile display the navigation bar.
Within Java, this method is called as follows:
public static void showNavigationBar()
Example 6-23 illustrates using this method.
Example 6-23 Showing the Navigation Bar in Java
import oracle.adfmf.framework.api.AdfmfContainerUtilties; ... try { AdfmfContainerUtilities.showNavigationBar(); }catch(Exception e) { // handle the exception }
In JavaScript, the success
and failed
callback functions enable the returned value and the exception to be passed back to the JavaScript calling code as follows:
public void showNavigationBar(success, failed)
The success
callback function must be in the form of function(request, response)
, where the request contains the original request and the response contains the associated method's return value (void
).
The failed
callback function must be in the form of function(request, response)
, where the request contains the original request and the response contains the error.
Example 6-24 illustrates using these callback functions.
This method invokes a Java method from any class in a classpath as follows:.
adf.mf.api.invokeMethod(classname, methodname, param1, param2, ... , paramN ,successCallback, failedCallback);
Table 6-1 lists the parameters taken by this method.
Table 6-1 Parameters Passed to invokeJavaMethod
Parameter | Description |
---|---|
|
The class name (including the package information) that ADF Mobile uses to create an instance when calling the Java method. |
|
The name of the method that should be invoked on the instance of the class specified by the |
The success
callback function must be in the form of function(request, response)
, where the request contains the original request and the response contains the associated method's return value.
The failed
callback function must be in the form of function(request, response)
, where the request contains the original request and the response contains the error.
Examples of using this method with multiple parameters are as follows:
adf.mf.api.invokeMethod("TestBean", "setStringProp", "foo", success, failed);
adf.mf.api.invokeMethod("TestBean", "getStringProp", success, failed);
An example of using an integer parameter is as follows:
adf.mf.api.invokeMethod("TestBean", "testSimpleIntMethod", "101", success, failed);
The following illustrates using complex parameters:
adf.mf.api.invokeMethod("TestBean", "testComplexMethod", {"foo":"newfoo","baz":"newbaz",".type":"TestBeanComplexSubType"}, success, failed);
The following illustrates using no parameters:
adf.mf.api.invokeMethod("TestBean", "getComplexColl", success, failed);
The following illustrates using String
parameters:
adf.mf.api.invokeMethod("TestBean", "testMethodStringStringString", "Hello ", "World", success, failed);
The invokeContainerJascriptFunction
invokes a JavaScript method. Table 6-2 lists the parameters passed by this method.
Table 6-2 Parameters Passed to invokeContainerJavaScriptFunction
Parameter | Description |
---|---|
|
The ID of the application feature used by ADF Mobile to determine the context for the JavaScript invocation. The ID determines the web view in which this method is called. |
|
The name of the method that should be invoked. |
|
An array of arguments that are passed to the method. Within this array, these arguments should be arranged in the order expected by the method. |
This method returns a JSON object.
Example 6-25 The invokeContainerJavaScriptFunction Method
public static java.lang.Object invokeContainerJavaScriptFunction(java.lang.String featureId, java.lang.Object[] args) throws oracle.adfmf.framework.exception.AdfException
Example 6-26 illustrates a JavaScript file called
appFunctions.js
that is included in the application feature, called feature1
. The JavaScript method, application.testFunction
which is described within this file, is called by the invokeContainerJavaScriptFunction method
, shown in Example 6-27. Because the application includes a command button that is configured with an action listener that calls this function, a user sees the following alerts after clicking this button:
APP ALERT 0
APP ALERT 1
APP ALERT 2
(function() { if (!window.application) window.application = {}; application.testFunction = function() { var args = arguments; alert("APP ALERT " + args.length + " "); return "application.testFunction - passed"; }; })();
Example 6-27 illustrates how the
invokeApplicationJavaScriptFunction
method calls the JavaScript method (application.testFunction
) that is described in Example 6-26.
Example 6-27 Calling the JavaScript Function
invokeApplicationJavaScriptFuntions public void invokeApplicationJavaScriptFuntions(ActionEvent actionEvent) { AdfmfContainerUtilities.invokeContainerJavaScriptFunction("feature1", "application.testFunction", new Object[] {} ); AdfmfContainerUtilities.invokeContainerJavaScriptFunction("feature1", "application.testFunction", new Object[] {"P1"} ); AdfmfContainerUtilities.invokeContainerJavaScriptFunction("feature1", "application.testFunction", new Object[] {"P1", "P2"} ); }
For more information, see Oracle Fusion Middleware Java API Reference for Oracle ADF Mobile.
In JavaScript, the success
and failed
callback functions enable the returned value and the exception to be passed back to the JavaScript calling code as follows:
public void invokeContainerJavaScriptFunction(success, failed)
The success
callback function must be in the form of function(request, response)
, where the request contains the original request and the response contains the associated method's return values, which are described in Table 6-2. The response contains the associated
AdfmfContainerUtilities
method's return value
The failed
callback function must be in the form of function(request, response)
, where the request contains the original request and the response contains the error.
The adfmfJavaUtilties
API includes the getDirectoryPathRoot
method. This method, which can only be called from the Java layer, enables access to files on iOS systems. As shown in Example 6-28, this method enables access to files packaged in an iOS application bundle (an
.ipa
file), the location of temporary files, and also the location of the cache directory on the device. For more information on oracle.adfmf.framework.api.AdfmfJavaUtilities
, see Oracle Fusion Middleware Java API Reference for Oracle ADF Mobile.
Example 6-28 Accessing Files on the iOS System
import oracle.adfmf.framework.api.AdfmfJavaUtilities; ... public void getDirectoryPathRoot() { // returns the directory for storing temporary files String tempDir = AdfmfJavaUtilities.getDirectoryPathRoot(AdfmfJavaUtilities.TemporaryDirectory); // returns the directory for storing application files String appDir = AdfmfJavaUtilities.getDirectoryPathRoot(AdfmfJavaUtilities.ApplicationDirectory); // returns the directory for storing cache files String deviceDir = AdfmfJavaUtilities.getDirectoryPathRoot(AdfmfJavaUtilities.DeviceOnlyDirectory); }