I wanted to figure out how to use WL.SimpleDialog() so i used it to change the contact application that i developed in
Using BusyIndicator common control so that if there is JavaScript Exception during searching of contact it displays that error in Dialog Box like this
This is how my JavaScript looks like after the changes
var busyIndicator;
function wlCommonInit(){
busyIndicator = new WL.BusyIndicator('page1');
}
function getContact(){
console.log("Entering getContact() REST service based version");
var contactName = $('contactName').getValue();
var invocationData = {
adapter:"ContactWSService",
procedure:"searchContact",
parameters:[contactName]
}
var options ={
onSuccess:loadContactSuccess,
onFailure:loadContactFailure
}
busyIndicator.show();
WL.Client.invokeProcedure(invocationData, options);
}
function loadContactSuccess(result){
console.log("Inside loadContactSuccess " + result);
var html = '';
try{
if(result.status == 200){
var contactList = result.invocationResult.Envelope.Body.
searchContactResponse.contactList;
var i = 0;
for(i =0 ; i < contactList.length ; i++){
var currentContact = contactList[i];
html = html + '<li><a href="#">'+currentContact.firstName
+' ' +currentContact.lastName +'</a></li>';
}
}
jq("#displayContact").html(html);
jq("#displayContact").listview('refresh');
busyIndicator.hide();
}catch(e){
busyIndicator.hide();
displayError(e.toString());
}
}
function loadContactFailure(result){
console.log("Inside loadContactError " + result);
busyIndicator.hide();
displayError(result);
}
function displayError(errorString) {
var dialogTitle = "Error";
WL.SimpleDialog.show(dialogTitle, errorString, [ {
text : 'OK',
handler : simpleDialogButton1Click
}
]);
}
function simpleDialogButton1Click() {
}
First i did create a
displayError()
method that takes error message as input and displays it in Modal dialog that has only one button. The simpleDialogButton1Click() would get called when user clicks on OK in the Error dialog but it does not do anything.
The displayError() method is getting called from the exception handler class as well as the loadContactFailure() class.
1 comment:
nice post,, thanks for sharing
Post a Comment