0

I'm getting a blank screen while running the code in the webpage. The adapter procedure alone is getting invoked correctly but I couldn't invoke it from my client side.I'm using Db2 database. Please help.

Here is my JavaScript code..

function loadDetails(x,y,z,a,b,c,d,e,f,g,h,i){

var x= document.getElementById("firstname").value;
var y= document.getElementById("lastname").value;
var z= document.getElementById("doorno").value;
var a= document.getElementById("streetname").value;

var b= document.getElementById("area").value;

var c= document.getElementById("zipcode").value;

var d= document.getElementById("landmark").value;

var e= document.getElementById("secques").value;

var f= document.getElementById("secans").value;

var g= document.getElementById("emailaddress").value;

var h= document.getElementById("username").value;

var i= document.getElementById("password").value;



var invocationData = {
        adapter : 'DBAdapter',
        procedure : 'addDBAdapter',
        parameters : [x,y,z,a,b,c,d,e,f,g,h,i]
    };

WL.Client.invokeProcedure(invocationData,{
    onSuccess : loadDetailsSuccess,
    onFailure : loadDetailsFailure

});

}

function loadDetailsSuccess(){

alert("Registration Successfull. Please login to continue...");
window.location.href = 'login.html';

}

function loadDetailsFailure(){

WL.Logger.error("load data failure");

}

DBAdapter-impl.js

var addStatement = WL.Server.createSQLStatement("insert into CUSTOMER(FIRSTNAME,LASTNAME,DOORNO,AREA,STREETNAME,ZIPCODE,LANDMARK,SECQUES,SECANS,EMAILADDRESS,USERNAME,PASSWORD) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)");

function addDBAdapter(x,y,z,a,b,c,d,e,f,g,h,i) {

return WL.Server.invokeSQLStatement({
    preparedStatement : addStatement,
    parameters : [x,y,z,a,b,c,d,e,f,g,h,i]
});

}

  • Please update a copy of your project to dropbox or some similar mechanism for further investigation. We really need to see the HTML code as well to see how you are calling these procedures. If you are looking for info on adapters as well as sample projects please look here (Under section 4 Worklight server-side development): http://public.dhe.ibm.com/software/mobile-solutions/worklight/docs/v610/04_01_Adapter_framework_overview.pdf – Joshua Alger Mar 11 '14 at 13:16
  • Did you try to invoke the procedure directly from eclipse? – Nathan H Mar 11 '14 at 13:33
  • 1
    Also, it's not very clear why the client side function loadDetails takes arguments but at the same time overwrites those arguments inside... – Nathan H Mar 11 '14 at 13:34
  • can you share your worklight project into dropbox? – Nurdin Mar 11 '14 at 17:23
  • 1
    Please note that Worklight hybrid apps are **single page**, you cannot use *window.location.href* to switch pages. Please have a look at the Getting Started module "Building a multi-page application" at http://www.ibm.com/developerworks/mobile/worklight/getting-started.html – eabe Mar 13 '14 at 08:19
  • At last I got it! Yeah its the problem with the 'window.location.href'. I implemented the 'multipage application' concept and the problem solved. Thanks a lot to Eabe and Idan :) Also thanks to everyone here :) – user3329569 Mar 14 '14 at 15:41

1 Answers1

0

As eabe rightly so mention in the comments, and we've all missed it(!), Worklight is a Single Page Application and indeed window.location.href = 'login.html'; seems to be the culprit here.

See this related question on this subject matter that also contain solutions:

Basically, you can use either jQuery's .load or jQuery Mobile's .changePage (or the equivalent of other libraries to do the same) in order to load the contents of another page, or "switch" to another. Doing what you do, you lost the Worklight "context" and nothing will work or display.

Also review this training material:

Community
  • 1
  • 1
Idan Adar
  • 44,156
  • 13
  • 50
  • 89