Simplifying Enterprise Mobility

Wednesday Mar 06, 2013

In this edition of the ADF Mobile blog I'll tackle a topic that many have asked about. How to invoke a custom Javascript method from an AMX page. We'll also cover how to call back to Java from the same Javascript method.

Adding the custom Javascript to your AMX

To include a javascript file to an AMX feature, you need to go to Content tab of the adfmf-feature.xml. This lets you include a javascript or CSS file. In this case, we'll be including our custom javacript file.

Invoking the Javascript from a Java handler

From any Java code, you can use a built in method of the AdfmfContainerUtilities utility class to invoke a Javascript method. Here's an example:

The above call invokes the "doAlert" method in the feature with featureid="feature1". The last parameter is an array of parameters that will be sent to the method. Here's an example of passing in 3 parameters:

Calling back to Java

In this method, the first parameter is the fully qualified Java class with the package name. The second parameter is the method to invoke. The second to last parameter is the javascript callback to be invoked on success and the last parameter is the javascript callback to be invoked when the function fails. Any parameters added between the method and success callback are passes as the parameters to the java method. Here are the signatures for the success and failure callbacks:

With this method, you can simply set the value of the EL expression. Note that the first parameter is a complex parameter that contains a JSON snippet that has a name/value pair. It has the usual success and failure callbacks.

About

This blog is is dedicated to announcements,tips and tricks and other items related to developing, integrating, securing, and managing mobile applications using Oracle's Mobile Platform. It is created and maintained by the Oracle Mobile product development team.