Using JQuery Mobile in WorkLight application

In the Connecting to Database from WorkLight i blogged about how to build WorkLight application that talks to database, that application did not had good looking UI, so i made changes to use JQuery Mobile that makes building good looking UI much simpler. This is how my application looks like now
These are the steps that i followed
  1. Create a simple WorkLight application that invokes a SQL query you can use the steps mentioned in Connecting to Database from WorkLight
  2. First download the Worklight Starter Application for JQuery Mobile from Worklight Getting started page
  3. Expand the some where on your local disk
  4. Copy*.js and jquery-*.js from the to the js folder of your application, Also copy*.css into css folder of your application
  5. Change the html page of your application to include the JQuery related css and js, this is how the html page looks for me
    <!DOCTYPE html>
    <meta charset="utf-8" />
    <meta name="viewport"
      content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0" />
    <link rel="shortcut icon" href="images/favicon.png" />
    <link rel="apple-touch-icon" href="images/apple-touch-icon.png" />
    <link rel="stylesheet" href="css/reset.css" />
    <link rel="stylesheet" href="css/HelloDatabase.css" />
    <link rel="stylesheet" href="css/" />
    <script src="js/jquery-1.7.1.min.js"></script>
      var jq = jQuery.noConflict();
    <script src="js/"></script>
    <body onload="WL.Client.init({})" id="content" style="display: none">
      <div data-role="page" id="page1">
        <div data-theme="a" data-role="header">
          <h3>Contact DB App</h3>
        <div data-role="content">
          <div data-role="fieldcontain">
                        <fieldset data-role="controlgroup">
                            <label for="textinput1">
                               First Name
                            <input id="contactName" placeholder="" value="" type="text" />
                    <a data-role="button" data-transition="fade" href="javascript:getContact()" id="searchContact">
                        Search Contact
          <ul data-role="listview" data-inset="true" data-filter="true" id="displayContact">
        <div data-theme="a" data-role="footer">
          <h3>Copyright stuff</h3>
      <script src="js/HelloDatabase.js"></script>
      <script src="js/messages.js"></script>
      <script src="js/auth.js"></script>
    In the head section first you should include jquery related css and js and also call var jq = jQuery.noConflict(); so that the jQuery $ character does not conflict with $ used by the prototype javascript framework used by worklight. Next use the jquery mobile template in the body section that divided the page into head, content and footer section.
  6. Add following code to the javascript file for your application
    function wlCommonInit(){
      // Common initialization code goes here
    function getContact(){
      console.log("Entering getContact()");
      var contactName = '%'+$('contactName').getValue()+'%';
      var invocationData = {
      var options ={
      WL.Client.invokeProcedure(invocationData, options);
    function loadContactSuccess(result){
      console.log("Inside loadContactSuccess " + result);
      var html = '';
        var contactList = result.invocationResult.resultSet;
        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>';
    function loadContactFailure(result){
      console.log("Inside loadContactError " + result);
    As you can can see i am using jq("#displayContact")> instead of regular $("#displayContact") this is the nonconflict version of JQuery that you must use in the WorkLight, but your still allowed to use the prototype based syntax for looking up objects as well like i did in $('contactName').getValue()

1 comment:

James said...

is it still necessary to get this custom version of jquery using worklight version 5?