{"id":1195,"date":"2014-03-25T14:30:45","date_gmt":"2014-03-25T09:00:45","guid":{"rendered":"http:\/\/ramkulkarni.com\/blog\/?p=1195"},"modified":"2014-03-25T14:30:45","modified_gmt":"2014-03-25T09:00:45","slug":"cfmobile-example-accessing-remote-data-from-mobile-application","status":"publish","type":"post","link":"http:\/\/ramkulkarni.com\/blog\/cfmobile-example-accessing-remote-data-from-mobile-application\/","title":{"rendered":"CFMobile Example &#8211; Accessing remote data from mobile application"},"content":{"rendered":"<p>So far I have posted CFMobile examples that were mostly standalone applications (except a <a title=\"CFMobile Example \u2013 Taking picture and uploading to ColdFusion server\" href=\"http:\/\/ramkulkarni.com\/blog\/cfmobile-example-taking-picture-and-uploading-to-coldfusion-server\/\" target=\"_blank\">photo application<\/a> that uploaded image to server). However many mobile applications may need to interact with server, for example to show data from a remote database, to modify data or for many other purposes.<\/p>\n<p>CFMobile features in <a href=\"http:\/\/labs.adobe.com\/technologies\/coldfusion\/\" target=\"_blank\">ColdFusion\u00a0Splendor<\/a> make accessing remote CF server very easy. I will demonstrate this using a simple example &#8211; I will build a mobile app that displays employee records fetched from a remote CF server. The client side (cfclient) code calls a CFC on the server side which fetches data and returns result to the calling page. You will see that creating and accessing a server side CFC is as easy as it is in a completely server side CFML code &#8211;\u00a0you don&#8217;t need to worry about writing code to make AJAX calls. cfclient does that for you transparently. I should mention here that this feature to call server CFCs from cfclient is not limited to mobile application, you can even use it for any web application.<\/p>\n<p>Here is a screenshot of the application &#8211;<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/138.197.85.232\/blog\/wp-content\/uploads\/2014\/03\/2014_03_25_image5.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1196\" data-permalink=\"http:\/\/ramkulkarni.com\/blog\/cfmobile-example-accessing-remote-data-from-mobile-application\/2014_03_25_image5\/\" data-orig-file=\"https:\/\/i0.wp.com\/ramkulkarni.com\/blog\/wp-content\/uploads\/2014\/03\/2014_03_25_image5.png?fit=480%2C800\" data-orig-size=\"480,800\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"2014_03_25_image5\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/ramkulkarni.com\/blog\/wp-content\/uploads\/2014\/03\/2014_03_25_image5.png?fit=180%2C300\" data-large-file=\"https:\/\/i0.wp.com\/ramkulkarni.com\/blog\/wp-content\/uploads\/2014\/03\/2014_03_25_image5.png?fit=480%2C800\" class=\"size-medium wp-image-1196 alignnone\" style=\"border: 1px solid black;\" src=\"https:\/\/i0.wp.com\/138.197.85.232\/blog\/wp-content\/uploads\/2014\/03\/2014_03_25_image5-180x300.png?resize=180%2C300\" alt=\"2014_03_25_image5\" width=\"180\" height=\"300\" srcset=\"https:\/\/i0.wp.com\/ramkulkarni.com\/blog\/wp-content\/uploads\/2014\/03\/2014_03_25_image5.png?resize=180%2C300 180w, https:\/\/i0.wp.com\/ramkulkarni.com\/blog\/wp-content\/uploads\/2014\/03\/2014_03_25_image5.png?w=480 480w\" sizes=\"(max-width: 180px) 100vw, 180px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p><!--more-->I will start with building the server side application. We need to create a database and a table on the server. I am going to use Embedded Apache Derby database for this application. Using ColdFusion Administrator, you can create both database and datasource for Embedded Apache Derby. Open up the administrator and go to &#8216;Data &amp; Services&#8217;-&gt;Data Sources page and add a new data source, called EmployeeDS &#8211;<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/138.197.85.232\/blog\/wp-content\/uploads\/2014\/03\/2014_03_25_image1.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1197\" data-permalink=\"http:\/\/ramkulkarni.com\/blog\/cfmobile-example-accessing-remote-data-from-mobile-application\/2014_03_25_image1\/\" data-orig-file=\"https:\/\/i0.wp.com\/ramkulkarni.com\/blog\/wp-content\/uploads\/2014\/03\/2014_03_25_image1.png?fit=539%2C220\" data-orig-size=\"539,220\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"2014_03_25_image1\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/ramkulkarni.com\/blog\/wp-content\/uploads\/2014\/03\/2014_03_25_image1.png?fit=300%2C122\" data-large-file=\"https:\/\/i0.wp.com\/ramkulkarni.com\/blog\/wp-content\/uploads\/2014\/03\/2014_03_25_image1.png?fit=525%2C214\" class=\"alignnone size-medium wp-image-1197\" src=\"https:\/\/i0.wp.com\/138.197.85.232\/blog\/wp-content\/uploads\/2014\/03\/2014_03_25_image1-300x122.png?resize=300%2C122\" alt=\"2014_03_25_image1\" width=\"300\" height=\"122\" srcset=\"https:\/\/i0.wp.com\/ramkulkarni.com\/blog\/wp-content\/uploads\/2014\/03\/2014_03_25_image1.png?resize=300%2C122 300w, https:\/\/i0.wp.com\/ramkulkarni.com\/blog\/wp-content\/uploads\/2014\/03\/2014_03_25_image1.png?w=539 539w\" sizes=\"(max-width: 300px) 100vw, 300px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>Click Add button, and you will see details page &#8211;<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/138.197.85.232\/blog\/wp-content\/uploads\/2014\/03\/2014_03_25_image2.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1198\" data-permalink=\"http:\/\/ramkulkarni.com\/blog\/cfmobile-example-accessing-remote-data-from-mobile-application\/2014_03_25_image2\/\" data-orig-file=\"https:\/\/i0.wp.com\/ramkulkarni.com\/blog\/wp-content\/uploads\/2014\/03\/2014_03_25_image2.png?fit=544%2C266\" data-orig-size=\"544,266\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"2014_03_25_image2\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/ramkulkarni.com\/blog\/wp-content\/uploads\/2014\/03\/2014_03_25_image2.png?fit=300%2C147\" data-large-file=\"https:\/\/i0.wp.com\/ramkulkarni.com\/blog\/wp-content\/uploads\/2014\/03\/2014_03_25_image2.png?fit=525%2C257\" class=\"alignnone size-medium wp-image-1198\" src=\"https:\/\/i0.wp.com\/138.197.85.232\/blog\/wp-content\/uploads\/2014\/03\/2014_03_25_image2-300x146.png?resize=300%2C146\" alt=\"2014_03_25_image2\" width=\"300\" height=\"146\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>Specify database folder and select &#8216;Create Database&#8217; option. I have created the database in cfusion\/db\/EmployeeDS folder. Derby database driver creates the last folder, so make sure EmployeeDS folder does not already exist in cfusion\/db, otherwise Derby throws error.<\/p>\n<p>We now need to create employee table. I have created a simple cfml file, db_scripts.cfm with functions to create database, list and delete \u00a0records.<!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: white; overflow: auto; width: auto; color: black; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #408080; font-style: italic;\">&lt;!--- Functions to create Employee databsase, display employees <\/span>\n<span style=\"color: #408080; font-style: italic;\">\tand delete all employees from the table ---&gt;<\/span>\n\n<span style=\"color: #408080; font-style: italic;\">&lt;!--- Comment call to function createTable after table is successfully created ---&gt;<\/span>\n<span style=\"color: #008000;\">&lt;cfset<\/span> <span style=\"color: #0000ff;\">createTable<\/span>()<span style=\"color: #008000;\">&gt;<\/span>\n\n<span style=\"color: #408080; font-style: italic;\">&lt;!---&lt;cfset deleteAll()&gt;---&gt;<\/span>\n\n<span style=\"color: #408080; font-style: italic;\">&lt;!---&lt;cfset listEmployees()&gt;---&gt;<\/span>\n\n<span style=\"color: #008000; font-weight: bold;\">&lt;br&gt;<\/span>Script Executed.\n\n<span style=\"color: #008000;\">&lt;cffunction<\/span> <span style=\"color: #19177c;\">name<\/span><span style=\"color: #666666;\">=<\/span><span style=\"color: #ba2121;\">\"createTable\"<\/span> <span style=\"color: #008000;\">&gt;<\/span>\n\n\t<span style=\"color: #008000; font-weight: bold;\">&lt;cfquery<\/span> <span style=\"color: #7d9029;\">datasource=<\/span><span style=\"color: #ba2121;\">\"employeeDS\"<\/span><span style=\"color: #008000; font-weight: bold;\">&gt;<\/span>\n\t\tcreate table employee (\n\t\t\tid integer not null generated always as identity,\n\t\t\tfirst_name varchar(20),\n\t\t\tlast_name varchar(20),\n\t\t\taddress varchar(100))\n\t<span style=\"color: #008000; font-weight: bold;\">&lt;\/cfquery&gt;<\/span>\n<span style=\"color: #008000;\">&lt;\/cffunction&gt;<\/span>\n\n<span style=\"color: #008000;\">&lt;cffunction<\/span> <span style=\"color: #19177c;\">name<\/span><span style=\"color: #666666;\">=<\/span><span style=\"color: #ba2121;\">\"deleteAll\"<\/span> <span style=\"color: #008000;\">&gt;<\/span>\n\t<span style=\"color: #008000; font-weight: bold;\">&lt;cfquery<\/span> <span style=\"color: #7d9029;\">datasource=<\/span><span style=\"color: #ba2121;\">\"EmployeeDS\"<\/span> <span style=\"color: #008000; font-weight: bold;\">&gt;<\/span>\n\t\tdelete from EMPLOYEE\n\t<span style=\"color: #008000; font-weight: bold;\">&lt;\/cfquery&gt;<\/span>\n<span style=\"color: #008000;\">&lt;\/cffunction&gt;<\/span>\n\n<span style=\"color: #008000;\">&lt;cffunction<\/span> <span style=\"color: #19177c;\">name<\/span><span style=\"color: #666666;\">=<\/span><span style=\"color: #ba2121;\">\"listEmployees\"<\/span> <span style=\"color: #008000;\">&gt;<\/span>\n\t<span style=\"color: #008000; font-weight: bold;\">&lt;cfquery<\/span> <span style=\"color: #7d9029;\">datasource=<\/span><span style=\"color: #ba2121;\">\"employeeDS\"<\/span> <span style=\"color: #7d9029;\">name=<\/span><span style=\"color: #ba2121;\">\"rs\"<\/span><span style=\"color: #008000; font-weight: bold;\">&gt;<\/span>\n\t\tselect * from EMPLOYEE order by FIRST_NAME\n\t<span style=\"color: #008000; font-weight: bold;\">&lt;\/cfquery&gt;<\/span>\n\n\t<span style=\"color: #008000; font-weight: bold;\">&lt;table<\/span> <span style=\"color: #008000; font-weight: bold;\">&gt;<\/span>\n\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;tr&gt;<\/span>\n\t\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;th&gt;<\/span>First Name<span style=\"color: #008000; font-weight: bold;\">&lt;\/th&gt;<\/span>\n\t\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;th&gt;<\/span>Last Name<span style=\"color: #008000; font-weight: bold;\">&lt;\/th&gt;<\/span>\n\t\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;th&gt;<\/span>Address<span style=\"color: #008000; font-weight: bold;\">&lt;\/th&gt;<\/span>\n\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;\/tr&gt;<\/span>\n\t\t<span style=\"color: #008000;\">&lt;cfoutput query=\"rs\"&gt;<\/span>\n\t\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;tr&gt;<\/span>\n\t\t\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;td&gt;<\/span>#<span style=\"color: #19177c;\">first_name<\/span>#<span style=\"color: #008000; font-weight: bold;\">&lt;\/td&gt;<\/span>\n\t\t\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;td&gt;<\/span>#<span style=\"color: #19177c;\">last_name<\/span>#<span style=\"color: #008000; font-weight: bold;\">&lt;\/td&gt;<\/span>\n\t\t\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;td&gt;<\/span>#<span style=\"color: #19177c;\">address<\/span>#<span style=\"color: #008000; font-weight: bold;\">&lt;\/td&gt;<\/span>\n\t\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;\/tr&gt;<\/span>\n\t\t<span style=\"color: #008000;\">&lt;\/cfoutput&gt;<\/span>\n\t<span style=\"color: #008000; font-weight: bold;\">&lt;\/table&gt;<\/span>\n<span style=\"color: #008000;\">&lt;\/cffunction&gt;<\/span><\/pre>\n<\/div>\n<p>Run this page and it will create employee table with fields id, first_name, last_name and address.<\/p>\n<p>Next I will create a server side CFC, EmployeeDBManager.cfc with two functions &#8211; getEmployees and addEmployee &#8211;<!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: white; overflow: auto; width: auto; color: black; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008000;\">&lt;cfcomponent<\/span> <span style=\"color: #008000;\">&gt;<\/span>\n\t<span style=\"color: #008000;\">&lt;cfset<\/span> <span style=\"color: #19177c;\">this.ds<\/span> <span style=\"color: #666666;\">=<\/span> <span style=\"color: #ba2121;\">\"employeeDS\"<\/span><span style=\"color: #008000;\">&gt;<\/span>\n\n\t<span style=\"color: #008000;\">&lt;cffunction<\/span> <span style=\"color: #19177c;\">name<\/span><span style=\"color: #666666;\">=<\/span><span style=\"color: #ba2121;\">\"getEmployees\"<\/span> <span style=\"color: #19177c;\">returntype<\/span><span style=\"color: #666666;\">=<\/span><span style=\"color: #ba2121;\">\"Array\"<\/span> <span style=\"color: #19177c;\">access<\/span><span style=\"color: #666666;\">=<\/span><span style=\"color: #ba2121;\">\"remote\"<\/span> <span style=\"color: #19177c;\">returnformat<\/span><span style=\"color: #666666;\">=<\/span><span style=\"color: #ba2121;\">\"JSON\"<\/span>\n\t\t<span style=\"color: #19177c;\">hint<\/span><span style=\"color: #666666;\">=<\/span><span style=\"color: #ba2121;\">\"Fetches employee rows from Employee table and returns array of EmployeeTO components\"<\/span><span style=\"color: #008000;\">&gt;<\/span>\n\n\t\t<span style=\"color: #008000;\">&lt;cfset<\/span> <span style=\"color: #19177c;\">result<\/span> <span style=\"color: #666666;\">=<\/span> <span style=\"color: #0000ff;\">ArrayNew<\/span>(<span style=\"color: #666666;\">1<\/span>)<span style=\"color: #008000;\">&gt;<\/span>\n\n\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;cfquery<\/span> <span style=\"color: #7d9029;\">datasource=<\/span><span style=\"color: #ba2121;\">\"#this.ds#\"<\/span> <span style=\"color: #7d9029;\">name=<\/span><span style=\"color: #ba2121;\">\"empRs\"<\/span><span style=\"color: #008000; font-weight: bold;\">&gt;<\/span>\n\t\t\tselect * from EMPLOYEE order by FIRST_NAME\n\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;\/cfquery&gt;<\/span>\n\n\t\t<span style=\"color: #008000;\">&lt;cfloop<\/span> <span style=\"color: #19177c;\">query<\/span><span style=\"color: #666666;\">=<\/span><span style=\"color: #ba2121;\">\"empRs\"<\/span><span style=\"color: #008000;\">&gt;<\/span>\n\t\t\t<span style=\"color: #008000;\">&lt;cfset<\/span> <span style=\"color: #008000; font-weight: bold;\">var<\/span> <span style=\"color: #19177c;\">empStruct<\/span> <span style=\"color: #666666;\">=<\/span> {<span style=\"color: #ba2121;\">\"id\"<\/span>:<span style=\"color: #19177c;\">id<\/span>, <span style=\"color: #ba2121;\">\"firstName\"<\/span>:<span style=\"color: #19177c;\">first_name<\/span>,\n\t\t\t\t\t\t\t\t\t<span style=\"color: #ba2121;\">\"lastName\"<\/span>: <span style=\"color: #19177c;\">last_name<\/span>, <span style=\"color: #ba2121;\">\"address\"<\/span>:<span style=\"color: #19177c;\">address<\/span>}<span style=\"color: #008000;\">&gt;<\/span>\n\t\t\t<span style=\"color: #008000;\">&lt;cfset<\/span> <span style=\"color: #0000ff;\">arrayAppend<\/span>(<span style=\"color: #19177c;\">result<\/span>,<span style=\"color: #19177c;\">empStruct<\/span>)<span style=\"color: #008000;\">&gt;<\/span>\n\t\t<span style=\"color: #008000;\">&lt;\/cfloop&gt;<\/span>\n\n\t\t<span style=\"color: #008000;\">&lt;cfreturn<\/span> <span style=\"color: #19177c;\">result<\/span><span style=\"color: #008000;\">&gt;<\/span>\n\n\t<span style=\"color: #008000;\">&lt;\/cffunction&gt;<\/span>\n\n\t<span style=\"color: #008000;\">&lt;cffunction<\/span> <span style=\"color: #19177c;\">name<\/span><span style=\"color: #666666;\">=<\/span><span style=\"color: #ba2121;\">\"addEmployee\"<\/span> <span style=\"color: #19177c;\">access<\/span><span style=\"color: #666666;\">=<\/span><span style=\"color: #ba2121;\">\"remote\"<\/span> <span style=\"color: #19177c;\">returntype<\/span><span style=\"color: #666666;\">=<\/span><span style=\"color: #ba2121;\">\"numeric\"<\/span>\n\t\t<span style=\"color: #19177c;\">hint<\/span><span style=\"color: #666666;\">=<\/span><span style=\"color: #ba2121;\">\"Inserts a new employee record in the able\"<\/span><span style=\"color: #008000;\">&gt;<\/span>\n\t\t<span style=\"color: #008000;\">&lt;cfargument<\/span> <span style=\"color: #19177c;\">name<\/span><span style=\"color: #666666;\">=<\/span><span style=\"color: #ba2121;\">\"emp\"<\/span> <span style=\"color: #19177c;\">type<\/span><span style=\"color: #666666;\">=<\/span><span style=\"color: #ba2121;\">\"struct\"<\/span> <span style=\"color: #008000;\">&gt;<\/span>\n\n\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;cfquery<\/span> <span style=\"color: #7d9029;\">datasource=<\/span><span style=\"color: #ba2121;\">\"#this.ds#\"<\/span> <span style=\"color: #7d9029;\">result=<\/span><span style=\"color: #ba2121;\">\"newEmpResult\"<\/span><span style=\"color: #008000; font-weight: bold;\">&gt;<\/span>\n\t\t\tinsert into EMPLOYEE (FIRST_NAME,LAST_NAME,ADDRESS) values (\n\t\t\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;cfqueryparam<\/span> <span style=\"color: #7d9029;\">cfsqltype=<\/span><span style=\"color: #ba2121;\">\"cf_sql_varchar\"<\/span> <span style=\"color: #7d9029;\">value=<\/span><span style=\"color: #ba2121;\">\"#emp.firstName#\"<\/span><span style=\"color: #008000; font-weight: bold;\">&gt;<\/span>,\n\t\t\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;cfqueryparam<\/span> <span style=\"color: #7d9029;\">cfsqltype=<\/span><span style=\"color: #ba2121;\">\"cf_sql_varchar\"<\/span> <span style=\"color: #7d9029;\">value=<\/span><span style=\"color: #ba2121;\">\"#emp.lastName#\"<\/span><span style=\"color: #008000; font-weight: bold;\">&gt;<\/span>,\n\t\t\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;cfqueryparam<\/span> <span style=\"color: #7d9029;\">cfsqltype=<\/span><span style=\"color: #ba2121;\">\"cf_sql_varchar\"<\/span> <span style=\"color: #7d9029;\">value=<\/span><span style=\"color: #ba2121;\">\"#emp.address#\"<\/span><span style=\"color: #008000; font-weight: bold;\">&gt;<\/span>\n\t\t\t)\n\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;\/cfquery&gt;<\/span>\n\n\t\t<span style=\"color: #008000;\">&lt;cfreturn<\/span> <span style=\"color: #19177c;\">newEmpResult.generatedKey<\/span><span style=\"color: #008000;\">&gt;<\/span>\n\t<span style=\"color: #008000;\">&lt;\/cffunction&gt;<\/span>\n\n<span style=\"color: #008000;\">&lt;\/cfcomponent&gt;<\/span><\/pre>\n<\/div>\n<p>Note that both the functions are marked remote (because they will be called from a cfclient block).<br \/>\ngetEmployee returns Array in JSON format. It returns array of Struct with fields id, fistName, lastName and address.<br \/>\naddEmployee takes Struct argument with the same fields as above, except id. It returns id of the newly added employee.<br \/>\nWe are done with the server side code for this application.<\/p>\n<p>Let&#8217;s now create the client side application. In index.cfm of the client app, I first create HTML UI and write some JavaScript event handlers.<!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: white; overflow: auto; width: auto; color: black; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #bc7a00;\"><!--<span class=\"hiddenSpellError\" pre=\"\"-->&lt;DOCTYPE html&gt;<\/span>\n\n<span style=\"color: #008000; font-weight: bold;\">&lt;script <\/span><span style=\"color: #7d9029;\">src=<\/span><span style=\"color: #ba2121;\">\"jquery-2.0.3.min.js\"<\/span> <span style=\"color: #008000; font-weight: bold;\">&gt;&lt;\/script&gt;<\/span>\n\n<span style=\"color: #008000; font-weight: bold;\">&lt;script &gt;<\/span>\n\t$(<span style=\"color: #008000;\">document<\/span>).ready(<span style=\"color: #008000; font-weight: bold;\">function<\/span>(){\n\n\t\t$(<span style=\"color: #008000;\">document<\/span>).on(<span style=\"color: #ba2121;\">\"click\"<\/span>,<span style=\"color: #ba2121;\">\"#addBtn\"<\/span>, <span style=\"color: #008000; font-weight: bold;\">function<\/span>(){\n\t\t\t<span style=\"color: #008000; font-weight: bold;\">var<\/span> firstName <span style=\"color: #666666;\">=<\/span> $(<span style=\"color: #ba2121;\">\"#fnTxt\"<\/span>).val();\n\t\t\t<span style=\"color: #008000; font-weight: bold;\">var<\/span> lastName <span style=\"color: #666666;\">=<\/span> $(<span style=\"color: #ba2121;\">\"#lnTxt\"<\/span>).val();\n\t\t\t<span style=\"color: #008000; font-weight: bold;\">var<\/span> city <span style=\"color: #666666;\">=<\/span> $(<span style=\"color: #ba2121;\">\"#cityTxt\"<\/span>).val();\n\n\t\t\t<span style=\"color: #008000; font-weight: bold;\">if<\/span> (firstName.trim().length <span style=\"color: #666666;\">==<\/span> <span style=\"color: #666666;\">0<\/span>)\n\t\t\t{\n\t\t\t\talert(<span style=\"color: #ba2121;\">\"First name is required\"<\/span>);\n\t\t\t\t<span style=\"color: #008000; font-weight: bold;\">return<\/span>;\n\t\t\t}\n\n\t\t\taddEmployee(firstName,lastName,city);\n\t\t});\n\t});\n<span style=\"color: #008000; font-weight: bold;\">&lt;\/script&gt;<\/span>\n\n<span style=\"color: #008000; font-weight: bold;\">&lt;style &gt;<\/span>\n\t<span style=\"color: #008000; font-weight: bold;\">th<\/span><span style=\"color: #666666;\">,<\/span><span style=\"color: #008000; font-weight: bold;\">td<\/span> {\n\t\t<span style=\"color: #008000; font-weight: bold;\">text-align<\/span><span style=\"color: #666666;\">:<\/span><span style=\"color: #008000; font-weight: bold;\">left<\/span>;\n\t}\n<span style=\"color: #008000; font-weight: bold;\">&lt;\/style&gt;<\/span>\n\n<span style=\"color: #008000; font-weight: bold;\">&lt;h2&gt;<\/span>CFMobile Demo:<span style=\"color: #008000; font-weight: bold;\">&lt;\/h2&gt;<\/span>\nThis application calls a CFC on the server side to get all employee records from a database table on the server.<span style=\"color: #008000; font-weight: bold;\">&lt;br&gt;<\/span>\nYou can add an employee by filling up following details and clicking Submit button.\nThis again makes call to a server CFC to add employee to the table.\n\n<span style=\"color: #008000; font-weight: bold;\">&lt;h3&gt;<\/span>Add Employee:<span style=\"color: #008000; font-weight: bold;\">&lt;\/h3&gt;<\/span>\n<span style=\"color: #008000; font-weight: bold;\">&lt;form&gt;<\/span>\n\t<span style=\"color: #008000; font-weight: bold;\">&lt;table<\/span> <span style=\"color: #008000; font-weight: bold;\">&gt;<\/span>\n\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;tr&gt;<\/span>\n\t\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;td&gt;<\/span>First Name:<span style=\"color: #008000; font-weight: bold;\">&lt;\/td&gt;<\/span>\n\t\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;td&gt;&lt;input<\/span> <span style=\"color: #7d9029;\">type=<\/span><span style=\"color: #ba2121;\">\"text\"<\/span> <span style=\"color: #7d9029;\">id=<\/span><span style=\"color: #ba2121;\">\"fnTxt\"<\/span><span style=\"color: #008000; font-weight: bold;\">&gt;<\/span>\n\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;\/tr&gt;<\/span>\n\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;tr&gt;<\/span>\n\t\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;td&gt;<\/span>Last Name:<span style=\"color: #008000; font-weight: bold;\">&lt;\/td&gt;<\/span>\n\t\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;td&gt;&lt;input<\/span> <span style=\"color: #7d9029;\">type=<\/span><span style=\"color: #ba2121;\">\"text\"<\/span> <span style=\"color: #7d9029;\">id=<\/span><span style=\"color: #ba2121;\">\"lnTxt\"<\/span><span style=\"color: #008000; font-weight: bold;\">&gt;<\/span>\n\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;\/tr&gt;<\/span>\n\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;tr&gt;<\/span>\n\t\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;td&gt;<\/span>City:<span style=\"color: #008000; font-weight: bold;\">&lt;\/td&gt;<\/span>\n\t\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;td&gt;&lt;input<\/span> <span style=\"color: #7d9029;\">type=<\/span><span style=\"color: #ba2121;\">\"text\"<\/span> <span style=\"color: #7d9029;\">id=<\/span><span style=\"color: #ba2121;\">\"cityTxt\"<\/span><span style=\"color: #008000; font-weight: bold;\">&gt;<\/span>\n\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;\/tr&gt;<\/span>\n\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;tr&gt;<\/span>\n\t\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;td<\/span> <span style=\"color: #7d9029;\">colspan=<\/span><span style=\"color: #ba2121;\">\"2\"<\/span><span style=\"color: #008000; font-weight: bold;\">&gt;<\/span>\n\t\t\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;button<\/span> <span style=\"color: #7d9029;\">type=<\/span><span style=\"color: #ba2121;\">\"button\"<\/span> <span style=\"color: #7d9029;\">id=<\/span><span style=\"color: #ba2121;\">\"addBtn\"<\/span><span style=\"color: #008000; font-weight: bold;\">&gt;<\/span>Add<span style=\"color: #008000; font-weight: bold;\">&lt;\/button&gt;<\/span>\n\t\t\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;button<\/span> <span style=\"color: #7d9029;\">type=<\/span><span style=\"color: #ba2121;\">\"reset\"<\/span><span style=\"color: #008000; font-weight: bold;\">&gt;<\/span>Reset<span style=\"color: #008000; font-weight: bold;\">&lt;\/button&gt;<\/span>\n\t\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;\/td&gt;<\/span>\n\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;\/tr&gt;<\/span>\n\t<span style=\"color: #008000; font-weight: bold;\">&lt;\/table&gt;<\/span>\n<span style=\"color: #008000; font-weight: bold;\">&lt;\/form&gt;<\/span>\n<span style=\"color: #008000; font-weight: bold;\">&lt;hr&gt;<\/span>\n\n<span style=\"color: #008000; font-weight: bold;\">&lt;h3&gt;<\/span>Employees:<span style=\"color: #008000; font-weight: bold;\">&lt;\/h3&gt;<\/span>\n<span style=\"color: #008000; font-weight: bold;\">&lt;table<\/span> <span style=\"color: #7d9029;\">id=<\/span><span style=\"color: #ba2121;\">\"empTable\"<\/span> <span style=\"color: #7d9029;\">width=<\/span><span style=\"color: #ba2121;\">\"100%\"<\/span><span style=\"color: #008000; font-weight: bold;\">&gt;<\/span>\n\t<span style=\"color: #008000; font-weight: bold;\">&lt;tr&gt;<\/span>\n\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;th&gt;<\/span>First Name<span style=\"color: #008000; font-weight: bold;\">&lt;\/th&gt;<\/span>\n\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;th&gt;<\/span>Last Name<span style=\"color: #008000; font-weight: bold;\">&lt;\/th&gt;<\/span>\n\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;th&gt;<\/span>City<span style=\"color: #008000; font-weight: bold;\">&lt;\/th&gt;<\/span>\n\t<span style=\"color: #008000; font-weight: bold;\">&lt;\/tr&gt;<\/span>\n<span style=\"color: #008000; font-weight: bold;\">&lt;\/table&gt;<\/span>\n\n<span style=\"color: #008000; font-weight: bold;\">&lt;cfclient&gt;<\/span>\n<span style=\"color: #408080; font-style: italic;\"><!--- All <span class=\"hiddenSpellError\" pre=\"All \">cfclient<\/span> code goes here ---><\/span>\n    <span style=\"color: #008000; font-weight: bold;\">&lt;cfscript&gt;<\/span>\n    <span style=\"color: #008000; font-weight: bold;\">&lt;\/cfscript&gt;<\/span>\n<span style=\"color: #008000; font-weight: bold;\">&lt;\/cfclient&gt;<\/span><\/pre>\n<\/div>\n<p>In the cfscript block in cfclient, I first instantiate the server side CFC, EmployeeDBManager, and then call getAllEmployees function.<!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: white; overflow: auto; width: auto; color: black; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008000; font-weight: bold;\">try<\/span>\n{\n\tempMgr <span style=\"color: #666666;\">=<\/span> <span style=\"color: #008000; font-weight: bold;\">new<\/span> EmpServerApp.EmployeeDBManager();\n}\n<span style=\"color: #008000; font-weight: bold;\">catch<\/span> (any e)\n{\n\talert(<span style=\"color: #ba2121;\">\"Error : \"<\/span> <span style=\"color: #666666;\">+<\/span> e.message);\n\tcfabort ();\n}\n\n<span style=\"color: #408080; font-style: italic;\">\/\/get all employees from the server and display in the above HTML table<\/span>\ngetAllEmployees();<\/pre>\n<\/div>\n<p>empMgr is a global variable. You can create page level variable also using variables prefix, i.e variables.empMgr.<br \/>\nNotice that you instantiate server CFC from cfclient block just as you would do it in server side code.<\/p>\n<p>In getAllEmployees, I call\u00a0getEmployees method of the server CFC. But before calling the server CFC, I set callback handler (function) which will be called when server function returns.<!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: white; overflow: auto; width: auto; color: black; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #408080; font-style: italic;\">\/\/Fetch employees data from server and display in the HTML table<\/span>\n<span style=\"color: #008000; font-weight: bold;\">function<\/span> getAllEmployees()\n{\n\t<span style=\"color: #008000; font-weight: bold;\">try<\/span>\n\t{\n\t\t<span style=\"color: #408080; font-style: italic;\">\/\/Set callback function on the server CFC, which will be<\/span>\n\t\t<span style=\"color: #408080; font-style: italic;\">\/\/called with the result<\/span>\n\t\tempMgr.setCallbackHandler(<span style=\"color: #008000; font-weight: bold;\">function<\/span>(callbackResult){\n\t\t\t<span style=\"color: #008000; font-weight: bold;\">var<\/span> employees <span style=\"color: #666666;\">=<\/span> callbackResult.result;\n\t\t\t<span style=\"color: #008000; font-weight: bold;\">var<\/span> empCount <span style=\"color: #666666;\">=<\/span> arrayLen(employees);\n\t\t\t<span style=\"color: #008000; font-weight: bold;\">for<\/span> (<span style=\"color: #008000; font-weight: bold;\">var<\/span> i <span style=\"color: #666666;\">=<\/span> <span style=\"color: #666666;\">1<\/span>; i <span style=\"color: #666666;\">&lt;=<\/span> empCount; i<span style=\"color: #666666;\">++<\/span>)\n\t\t\t{\n\t\t\t\taddEmpToHTMLTable(employees[i]);\n\t\t\t}\n\t\t});\n\n\t\tempMgr.getEmployees();\n\t}\n\t<span style=\"color: #008000; font-weight: bold;\">catch<\/span> (any e)\n\t{\n\t\talert(<span style=\"color: #ba2121;\">\"Error : \"<\/span> <span style=\"color: #666666;\">+<\/span> e.message);\n\t\t<span style=\"color: #008000; font-weight: bold;\">return<\/span>;\n\t}\n\n}<\/pre>\n<\/div>\n<p>If you do not set the callback handler, remote CFC function would be called synchronously, which will block application UI till the CFC function returns. So make sure you set callback handler when invoking remote CFC function from cfclient.<\/p>\n<p>Argument to the callbakc handler is an object with result field. This field actually contains result returned by the remote CFC function. getEmployee function of the CFC returns array (of struct\/object), so I iterate over it and call addEmpToHTMLTable function for each employee struct.<!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: white; overflow: auto; width: auto; color: black; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #408080; font-style: italic;\">&lt;!--- Append employee data in the HTML table ---&gt;<\/span>\n<span style=\"color: #008000;\">&lt;cffunction<\/span> <span style=\"color: #19177c;\">name<\/span><span style=\"color: #666666;\">=<\/span><span style=\"color: #ba2121;\">\"addEmpToHTMLTable\"<\/span> <span style=\"color: #008000;\">&gt;<\/span>\n\t<span style=\"color: #008000;\">&lt;cfargument<\/span> <span style=\"color: #19177c;\">name<\/span><span style=\"color: #666666;\">=<\/span><span style=\"color: #ba2121;\">\"emp\"<\/span> <span style=\"color: #008000;\">&gt;<\/span>\n\n\t<span style=\"color: #008000;\">&lt;cfoutput &gt;<\/span>\n\t\t<span style=\"color: #008000;\">&lt;cfsavecontent<\/span> <span style=\"color: #19177c;\">variable<\/span><span style=\"color: #666666;\">=<\/span><span style=\"color: #ba2121;\">\"rowHtml\"<\/span> <span style=\"color: #008000;\">&gt;<\/span>\n\t\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;tr&gt;<\/span>\n\t\t\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;td&gt;<\/span>#<span style=\"color: #19177c;\">emp.firstName<\/span>#<span style=\"color: #008000; font-weight: bold;\">&lt;\/td&gt;<\/span>\n\t\t\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;td&gt;<\/span>#<span style=\"color: #19177c;\">emp.lastName<\/span>#<span style=\"color: #008000; font-weight: bold;\">&lt;\/td&gt;<\/span>\n\t\t\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;td&gt;<\/span>#<span style=\"color: #19177c;\">emp.address<\/span>#<span style=\"color: #008000; font-weight: bold;\">&lt;\/td&gt;<\/span>\n\t\t\t<span style=\"color: #008000; font-weight: bold;\">&lt;\/tr&gt;<\/span>\n\t\t<span style=\"color: #008000;\">&lt;\/cfsavecontent&gt;<\/span>\n\t<span style=\"color: #008000;\">&lt;\/cfoutput&gt;<\/span>\n\n\t<span style=\"color: #008000;\">&lt;cfset<\/span> <span style=\"color: #0000ff;\">$<\/span>(<span style=\"color: #ba2121;\">\"##empTable\"<\/span>).<span style=\"color: #0000ff;\">append<\/span>(<span style=\"color: #19177c;\">rowHtml<\/span>)<span style=\"color: #008000;\">&gt;<\/span>\n<span style=\"color: #008000;\">&lt;\/cffunction&gt;<\/span><\/pre>\n<\/div>\n<p>There is one more function in the cfscript block of cfclient, to add new employee<!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: white; overflow: auto; width: auto; color: black; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #408080; font-style: italic;\">\/\/Add a new employee.<\/span>\n<span style=\"color: #008000; font-weight: bold;\">function<\/span> addEmployee(firstName, lastName, city)\n{\n\t<span style=\"color: #008000; font-weight: bold;\">try<\/span>\n\t{\n\t\t<span style=\"color: #008000; font-weight: bold;\">var<\/span> newEmp <span style=\"color: #666666;\">=<\/span> {<span style=\"color: #ba2121;\">\"firstName\"<\/span><span style=\"color: #666666;\">:<\/span>firstName, <span style=\"color: #ba2121;\">\"lastName\"<\/span><span style=\"color: #666666;\">:<\/span>lastName, <span style=\"color: #ba2121;\">\"address\"<\/span><span style=\"color: #666666;\">:<\/span>city};\n\n\t\t<span style=\"color: #408080; font-style: italic;\">\/\/Set callback function on the server CFC, which will be<\/span>\n\t\t<span style=\"color: #408080; font-style: italic;\">\/\/called with the result<\/span>\n\t\tempMgr.setCallbackHandler(<span style=\"color: #008000; font-weight: bold;\">function<\/span>(callbackResult) {\n\t\t\tnewEmp.id <span style=\"color: #666666;\">=<\/span> callbackResult.result;\n\t\t\taddEmpToHTMLTable(newEmp);\n\t\t});\n\n\t\tempMgr.addEmployee(newEmp);\n\t}\n\t<span style=\"color: #008000; font-weight: bold;\">catch<\/span> (any e)\n\t{\n\t\talert(<span style=\"color: #ba2121;\">\"Error:\"<\/span> <span style=\"color: #666666;\">+<\/span> e.message);\n\t\t<span style=\"color: #008000; font-weight: bold;\">return<\/span>;\n\t}\n}<\/pre>\n<\/div>\n<p>addEmployee (in cfclient) takes three arguments &#8211; \u00a0firstName, lastName and city (address). I create a new struct using these arguments and pass it to addEmployee method of the remote CFC (EmployeeDBManager). Here also I set the callback handler because I don&#8217;t want call to a server function blocking the application.<br \/>\naddEmployee function on the server side returns id of the new employee. I get this as result field of the argument to callback handler. Then I call\u00a0addEmpToHTMLTable (see above) to append new employee to the HTML table.<\/p>\n<p>This completes code for the application. You can open index.cfm of the client application in Chrome\/Safari and see how the application works. You can also test it on mobile as a standalone application using PhoneGap Shell app that we have built (see links in my earlier post &#8211;\u00a0<a title=\"Simplify Mobile Application Development Using ColdFusion\" href=\"http:\/\/ramkulkarni.com\/blog\/simplify-mobile-application-development-using-coldfusion\/\" target=\"_blank\">Simplify Mobile Application Development Using ColdFusion<\/a>).<\/p>\n<p>However if you package the client application and install it on mobile device, you will find that application does not work &#8211; no data is fetched from the server.<br \/>\nWhen resolving URL of remote CFC in cfclient, the framework tries to resolve it from the URL of the client page. If client page and server CFC are loaded from the same server, which is what happens when you run the application in desktop browser or in the Shell application, cfclient is able to resolve the server CFC. But it cannot resolve it in a packaged application, because the client page is loaded locally from the device and server side CFC does not exist on the device.<\/p>\n<p>To help resolve server CFCs (used in cfclient), you need to provide base URL of the server when packaging the application. You do that by going to project properties (right click the project in the Navigator view of ColdFusion Thunder and select Properties menu option)-&gt;ColdFusion Mobile Project-&gt;\u00a0Miscellaneous page and specifying &#8216;Application Base URL&#8217;<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/138.197.85.232\/blog\/wp-content\/uploads\/2014\/03\/2014_03_25_image4.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1199\" data-permalink=\"http:\/\/ramkulkarni.com\/blog\/cfmobile-example-accessing-remote-data-from-mobile-application\/2014_03_25_image4\/\" data-orig-file=\"https:\/\/i0.wp.com\/ramkulkarni.com\/blog\/wp-content\/uploads\/2014\/03\/2014_03_25_image4.png?fit=700%2C164\" data-orig-size=\"700,164\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"2014_03_25_image4\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/ramkulkarni.com\/blog\/wp-content\/uploads\/2014\/03\/2014_03_25_image4.png?fit=300%2C70\" data-large-file=\"https:\/\/i0.wp.com\/ramkulkarni.com\/blog\/wp-content\/uploads\/2014\/03\/2014_03_25_image4.png?fit=525%2C123\" class=\"alignnone  wp-image-1199\" src=\"https:\/\/i0.wp.com\/138.197.85.232\/blog\/wp-content\/uploads\/2014\/03\/2014_03_25_image4-300x70.png?resize=300%2C70\" alt=\"2014_03_25_image4\" width=\"300\" height=\"70\" srcset=\"https:\/\/i0.wp.com\/ramkulkarni.com\/blog\/wp-content\/uploads\/2014\/03\/2014_03_25_image4.png?resize=300%2C70 300w, https:\/\/i0.wp.com\/ramkulkarni.com\/blog\/wp-content\/uploads\/2014\/03\/2014_03_25_image4.png?w=700 700w\" sizes=\"(max-width: 300px) 100vw, 300px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>When you right click on the project and select &#8216;Generate PhoneGap Build&#8217; menu option, the above URL will be used in the generated code to resolve server side CFCs.<\/p>\n<p>You also need to provide access to the external server from your mobile application. To do that, go to PhoneGap tab (in Mobile Project Properties) and click \u00a0New button. Go to Access page and type IP of the external (CF 11) server or * to allow access to any external server.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/138.197.85.232\/blog\/wp-content\/uploads\/2014\/03\/2014_03_25_image6.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1237\" data-permalink=\"http:\/\/ramkulkarni.com\/blog\/cfmobile-example-accessing-remote-data-from-mobile-application\/2014_03_25_image6\/\" data-orig-file=\"https:\/\/i0.wp.com\/ramkulkarni.com\/blog\/wp-content\/uploads\/2014\/03\/2014_03_25_image6.png?fit=539%2C192\" data-orig-size=\"539,192\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"2014_03_25_image6\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/ramkulkarni.com\/blog\/wp-content\/uploads\/2014\/03\/2014_03_25_image6.png?fit=300%2C107\" data-large-file=\"https:\/\/i0.wp.com\/ramkulkarni.com\/blog\/wp-content\/uploads\/2014\/03\/2014_03_25_image6.png?fit=525%2C187\" class=\"alignnone size-medium wp-image-1237\" src=\"https:\/\/i0.wp.com\/138.197.85.232\/blog\/wp-content\/uploads\/2014\/03\/2014_03_25_image6-300x106.png?resize=300%2C106\" alt=\"2014_03_25_image6\" width=\"300\" height=\"106\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>Download <a href=\"http:\/\/ramkulkarni.com\/temp\/2014-03-25\/EmpMobileAndServerProjects.zip\" target=\"_blank\">CFBuilder projects for this application<\/a>. EmpMobileApp folder in this zip contains client side application and EmpServerApp folder contains server side app. I am not providing Android APK file for this app because my server side CFC will not be accessible from this APK when you install it on you device.<\/p>\n<p>Though I showed you how to access remote database from CFMobile application in this post, the\u00a0technique\u00a0is not limited to database access. Server CFC can get data from any source and return to cfclient.<\/p>\n<p>-Ram Kulkarni<\/p>\n<p><span style=\"color: red;\">Update :<\/span> Final build of ColdFusion 11 has a bug because of which access to CFC on the server does not work. To fix this issue, copy <a href=\"http:\/\/ramkulkarni.com\/temp\/2014-03-25\/cfclient_main.js\" target=\"_blank\">cfclient_main.js<\/a> to wwwroot\/CFIDE\/cfclient folder of the server. Make sure you keep back-up of the old file before you overwrite it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So far I have posted CFMobile examples that were mostly standalone applications (except a photo application that uploaded image to server). However many mobile applications may need to interact with server, for example to show data from a remote database, to modify data or for many other purposes. CFMobile features in ColdFusion\u00a0Splendor make accessing remote &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/ramkulkarni.com\/blog\/cfmobile-example-accessing-remote-data-from-mobile-application\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;CFMobile Example &#8211; Accessing remote data from mobile application&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[32,23,78,1],"tags":[100,85,94,22,24],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2g9O8-jh","jetpack-related-posts":[],"_links":{"self":[{"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/posts\/1195"}],"collection":[{"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/comments?post=1195"}],"version-history":[{"count":0,"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/posts\/1195\/revisions"}],"wp:attachment":[{"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/media?parent=1195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/categories?post=1195"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ramkulkarni.com\/blog\/wp-json\/wp\/v2\/tags?post=1195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}