Search code examples
javascriptjavaoracle-maf

Oracle MAF : (Signature Capture) Calling a javascript function from Managed Bean


I'm following this tutorial to get signature capture functionality in Oracle MAF application.

When I tried with simple POC as explained in the tutorial, I made it work with out any issues. Same logic I have integrated into my project.


Following are the settings I have done for integration,

  • I have included js and css file into maf-feature.xml under Task flow definition (where i'm having amx page).
  • I have defined scope of the bean as pageFlow inside XXXXX-task-flow.xml file instead of adfc-mobile-config.xml like below,

    <managed-bean id="__20">
      <managed-bean-name>signatureCapture</managed-bean-name>
      <managed-bean-class>package.SignatureCapture</managed-bean-class>
      <managed-bean-scope>pageFlow</managed-bean-scope>
    </managed-bean>
    
  • when I'm calling fetchHandler and cleaHandler method using below commandButton, it is calling method without Fail.

From the method, below statement is not triggering JavaScript

In fetchHandler method:

AdfmfContainerUtilities.invokeContainerJavaScriptFunction(AdfmfJavaUtilities.getActiveContextId(), "doFetch",
                                                              new Object[] { });

In clearHandler method:

AdfmfContainerUtilities.invokeContainerJavaScriptFunction(AdfmfJavaUtilities.getActiveContextId(), "doClear",
                                                              new Object[] { });

Below is the JavaScript (MyFile.js) for you reference,

(function () {

    // This method clears the signature area
    doClear = function () {
    alert("Clear function called.!");
        var sigElement = document.getElementById("sig");
        if (sigElement == null)
            alert("sigElement not found");
        var sig = $(sigElement);
        sig.signature('clear');
        adf.mf.api.invokeMethod("package.SignatureCapture", "FetchCallback", "", onInvokeSuccess, onFail);
    };

    // This method gets the signature as a JSON string.  As an example, it does an alert of the string and then sends it to a Java handler for further processing
    doFetch = function () {
    alert("Fetch function called.!");
        var sigElement = document.getElementById("sig");
        if (sigElement == null)
            alert("sigElement not found");
        var sig = $(sigElement);
        var fetchData = sig.signature('toJSON');
        adf.mf.api.invokeMethod("package.SignatureCapture", "FetchCallback", fetchData, onInvokeSuccess, onFail);
    };

    function onInvokeSuccess(param) {
    alert("onInvokeSuccess");
    };

    function onFail() {
        alert("It failed");
    };

})();

Any suggestion would be appreciated. Please comment below, if you need any more details regarding this.


Solution

  • Instead of AdfmfJavaUtilities.getActiveContextId(), try to use your feature ID (as a string).

    From the Oracle documentation (click):

    public static Object invokeContainerJavaScriptFunction(String featureId,
                                                           String methodName,
                                                           Object[] args)
    

    Parameters:

    • featureId: The id of the feature on which to invoke the method
    • methodName: method name
    • args: array of arguments to be passed to method

    Returns:

    • a JSON object

    So like you can see/said yourself AdfmfJavaUtilities.getActiveContextId() doesn't return the featureID but the name of the current feature's active EL context (click)