Question

I am following this WebSphere Commerce guide for Worklight store fronts, to use Hybrid applications using IBM Worklight 5.0.5.

The application launches successfully, however after setting up the connection details for the store front in the app, and saving them - the store front, which is another Worklight Hybrid app located on a WebSphere Commerce server, is not initializing correctly.

Instead of loading correctly, I get this error message:

Uncaught TypeError: Cannot call method 'init' of undefined at 192.168.16.96/wcsstore/Aurora/mobile20/WorklightHybrid/android/js/initOptionsApp‌​‌​‌​.js:64

HTML File Code:

<body id="content" class="bg_splash" style="display: none;">
    <!-- application UI goes here -->
    <div class="wrapper">
        <div id="splashscreen" class="splash_logo_container splash_logo_position splash_logo"></div>
        <div id="pagePort" class="hidden"></div>
    </div>
    <script src="js/version.js"></script>
    <script src="js/messages.js"></script>
    <script src="js/messages_en_US.js"></script>
    <script src="js/messages_fr_FR.js"></script>
    <script src="js/messages_de_DE.js"></script>
    <script src="js/messages_it_IT.js"></script>
    <script src="js/messages_es_ES.js"></script>
    <script src="js/messages_pt_BR.js"></script>
    <script src="js/messages_zh_CN.js"></script>
    <script src="js/messages_zh_TW.js"></script>
    <script src="js/messages_ko_KR.js"></script>
    <script src="js/messages_ja_JP.js"></script>
    <script src="js/messages_ko_KR.js"></script>
    <script src="js/messages_ru_RU.js"></script>
    <script src="js/messages_ro_RO.js"></script>
    <script src="js/messages_pl_PL.js"></script>
    <script src="js/WCLocalStorage.js"></script>
    <script src="js/WCHybrid.js"></script>
    <script src="js/initOptions.js"></script>
</body>

initOptions.js

//Worklight Client initialization parameter array
var wlInitOptions = {
//Application should not attempt to connect to Worklight Server on application start up
connectOnStartup : false,
//Should application produce logs
enableLogger : true,
//Should direct updates prompt the user or occur silently
updateSilently: false
};

var initOptionsApp = (function() {

return {
    /**
     * Called when Cordova runtime has initialized
     */
    onDeviceReady: function() {
        var METHODNAME = "initOptionsApp.onDeviceReady";
        if (wlInitOptions.enableLogger) {
            WL.Logger.debug(METHODNAME, "ENTRY");
        }          
        //bind the hardware back button event listener
        document.addEventListener("backbutton", WCHybridApp.onBackKeyDown, false);
        if (wlInitOptions.enableLogger) {
            WL.Logger.debug(METHODNAME, "EXIT");
        }
    }
};

})();

/**
* Bind the Worklight Client initialization call to the page load event
*/
if (window.addEventListener) {
window.addEventListener('load', function() { WL.Client.init(wlInitOptions); }, false);
window.addEventListener('unload', function() { WCHybridApp.updateHistory(); }, false);
} else if (window.attachEvent) {
window.attachEvent('onload',  function() { WL.Client.init(wlInitOptions); });
}

/**
 * Bind events to the Cordova deviceready event
 */
if (document.addEventListener) {
document.addEventListener("deviceready", initOptionsApp.onDeviceReady, false);
}

Edit: The below was fixed after upgrading to Worklight 5.0.6.1

When I load my application on emulator its prompt unexpected three different dialog as can be seen in the images below.

enter image description here More examples here:

Was it helpful?

Solution

Getting these Cordova-related dialogs usually means something is not right with the Cordova version you're using in your application.

I strongly suggest starting fresh with Eclipse Java EE 4.2.2 (Juno SR2), and installing the Worklight Developer Edition (v5.0.6.1 from the Eclipse Marketplace). This will likely solve it.

Edit: From the edited question, it has.

The reamining issue with initOptions currently resembles this one: Uncaught ReferenceError: wlInitOptions is not defined

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top