APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle...
Transcript of APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle...
![Page 1: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/1.jpg)
APEX UnpluggedBuilding Oracle Application Express Applications That Can Survive
Without the Internet
Dan McGhanSenior Technical Consultant
1
![Page 2: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/2.jpg)
My background
Dan McGhan
Senior consultant with Enkitec
Joined in March 2013
Co-Author, Expert Oracle Application
Express
Regular presenter at various conferences
A.K.A “that guy that wrote that plug-in”
2
![Page 3: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/3.jpg)
About Enkitec
3
Oracle Platinum Partner
Established in 2004
Headquartered in Dallas, TX
Locations throughout the US & EMEA
Specialties include
Exadata Implementations
Development Services
PL/SQL / Java / APEX
DBA/Data Warehouse/RAC
Business Intelligence
![Page 4: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/4.jpg)
![Page 5: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/5.jpg)
![Page 6: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/6.jpg)
Cache Manifest
On/Offline Events
Local Storage
New tools
6
![Page 7: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/7.jpg)
Cache Manifest
On/Offline Events
Local Storage
New tools with 2 apps
7
![Page 8: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/8.jpg)
![Page 9: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/9.jpg)
![Page 10: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/10.jpg)
![Page 11: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/11.jpg)
![Page 12: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/12.jpg)
APEX Unplugged???
A more accurate title:
How to create an APEX application such that when the
Internet is not available it can switch to a cached offline
application with reduced functionality and then
synchronize with the online application when the Internet
is available again
12
![Page 13: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/13.jpg)
No longer just theory
Concepts have been implemented successfully
Now 2 good use cases
Survive offline
Most logic done in APEX
Minimal custom code
Thrive offline
APEX provides authentication and means to download and upload data
Mostly custom code
13
![Page 14: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/14.jpg)
Part 1:
Creating the base applications
14
![Page 15: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/15.jpg)
Demo
Creating the online APEX application
3 pages: Home, Listview & Form combo on emp
Just use the wizard
15
![Page 16: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/16.jpg)
Demo
Creating the offline JQM application
Created offline directory in listener docroot
Added jQuery & JQM
3 pages that mimic the online pages
16
![Page 17: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/17.jpg)
Part 2:
Making the JQM app offline(able)
17
![Page 18: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/18.jpg)
Cache Manifest basics
HTML5 storage feature
Allows access to web apps without a network connection
Tells browsers to store files indefinitely
Really just a file that lists required files
File must be served with MIME type: text/cache-manifest
Must be added to HTML element of app
18
![Page 19: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/19.jpg)
Adding the MIME type to glassfish
Modify default-web.xml
GLASSFISH_HOME\domains\domain1\config
19
![Page 20: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/20.jpg)
A simple example
20
<!-- clock.html -->
<!DOCTYPE HTML>
<html>
<head>
<title>Clock</title>
<script src="clock.js"></script>
<link rel="stylesheet" href="clock.css">
</head>
<body>
<p>The time is: <output id="clock"></output></p>
</body>
</html>
/* clock.css */
output { font: 2em sans-serif; }
/* clock.js */
setInterval(function () {
document.getElementById('clock').value = new Date();
}, 1000);
![Page 21: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/21.jpg)
Adding a cache manifest
21
CACHE MANIFEST
clock.html
clock.css
clock.js
<!-- clock.html -->
<!DOCTYPE HTML>
<html manifest="clock.appcache">
<head>
<title>Clock</title>
<script src="clock.js"></script>
<link rel="stylesheet" href="clock.css">
</head>
<body>
<p>The time is: <output id="clock"></output></p>
</body>
</html>
![Page 22: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/22.jpg)
My cache manifest
22
CACHE MANIFEST
CACHE:
/offline/index.html
/offline/employees.html
/offline/employee-details.html
/offline/libraries/custom/hr.js
/offline/libraries/jquery-mobile/jquery.min.js
/offline/libraries/jquery-mobile/jquery.min.map
/offline/libraries/jquery-mobile/jquery.mobile-1.3.2.min.css
/offline/libraries/jquery-mobile/jquery.mobile-1.3.2.min.js
/offline/libraries/jquery-mobile/jquery.mobile-1.3.2.min.map
/offline/libraries/jquery-mobile/images/ajax-loader.gif
/offline/libraries/jquery-mobile/images/icons-18-black.png
/offline/libraries/jquery-mobile/images/icons-18-white.png
/offline/libraries/jquery-mobile/images/icons-36-black.png
/offline/libraries/jquery-mobile/images/icons-36-white.png
NETWORK:
*
FALLBACK:
/ /offline/index.html
![Page 23: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/23.jpg)
Including the cache manifest
In the APEX app
Convenient, no need to go to offline application
Ended up with multiple masters due to APEX URLs
In the JQM app
Requires visit to JQM app to cache application
Cleaner, only caches what you want
23
![Page 24: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/24.jpg)
Chrome and the cache manifest
Developer tools
24
![Page 25: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/25.jpg)
Chrome and the cache manifest
AppCache Internals
25
![Page 26: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/26.jpg)
Demo
Going offline
Added cache manifest
Pointed index.html to cache manifest
26
![Page 27: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/27.jpg)
Part 3:
Transitioning between on/offline
27
![Page 28: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/28.jpg)
4 main timings to address
Online app not available
Already handled via fallback in cache manifest
User explicitly goes offline or online
Ajax request fails
Need to update offline app
28
![Page 29: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/29.jpg)
Problem: User goes offline
Some browsers offer an explicit offline mode
Others determine offline automatically
Airplane mode
Unplug the network cable
Disable wireless
Can vary by browser manufacture
What should happen if one is connected to a network but
without Internet connectivity?
Need to provide transition to offline app
29
![Page 30: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/30.jpg)
Solution
Browsers have online/offline events
Triggered on the window object
navigator.onLine provides access to current status
JavaScript added to app
30
WHEN offline event triggered
remove home icon
add button to offline app
END WHEN
ONLINE
WHEN online event triggered
remove button to offline app
add home icon
END WHEN
![Page 31: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/31.jpg)
Problem: User goes online
What goes offline can come back online
Need to provide transition to offline app
To avoid logging in again we need the APEX
session
But where should we get it from?
31
![Page 32: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/32.jpg)
Local storage
Local storage provides client side storage
Better than cookies as data isn’t transferred
5MB maximum per domain
Everything stored as strings
32
![Page 33: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/33.jpg)
Saving APEX session in LS
Use local storage to save session id
33
![Page 34: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/34.jpg)
Chrome and local storage
Developer tools
34
![Page 35: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/35.jpg)
Solution
JavaScript added to app
35
OFFLINE
WHEN online event triggered
add button to online app
END WHEN
WHEN offline event triggered
remove button to online app
END WHEN
![Page 36: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/36.jpg)
Demo
Handling user explicitly going offline or online
36
![Page 37: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/37.jpg)
Problem: Ajax request fails
Mobile apps load pages and other content via Ajax
If Ajax is used without connectivity an error will
occur
37
![Page 38: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/38.jpg)
Solution
Utilize jQuery’s Ajax error handler
JavaScript added to app
38
ONLINE
WHEN ajax error
redirect to offline app
END WHEN
![Page 39: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/39.jpg)
Demo
Handling failed Ajax requests
39
![Page 40: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/40.jpg)
Problem: Offline app updated
At some point you may update the offline app
But the browser cached old versions of the files
Will not go out and grab newer files automatically
40
![Page 41: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/41.jpg)
Solution
Tell the browser to update the cache
Automatically done on load if cache manifest is modified
Pragmatically via applicationCache.update()
Browser will download files and trigger events
Events triggered for downloading, updating, errors…
May need to manually swap in the new cache
Just reload the page
41
![Page 42: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/42.jpg)
Using comments to force updates
Some updates will involve adding/removing files
This requires the cache manifest be updated
The update to the manifest causes the browser to
download the files again
Some updates will only modify existing files
Changing the cache manifest is not technically required
Making changes to comments can serve as a workaround
42
CACHE MANIFEST
#version 1
![Page 43: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/43.jpg)
Solution
JavaScript added to app
JavaScript added to app
43
OFFLINE
WHEN app cache event triggered
IF app cache update ready
THEN
reload page
END IF
END WHEN
ONLINE
WHEN new app version available
add link to offline app
END WHEN
![Page 44: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/44.jpg)
Demo
Handling offline app updates
44
![Page 45: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/45.jpg)
Part 4:
Working with JSON & Local Storage
45
![Page 46: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/46.jpg)
JSON
JavaScript Object Notation
Simple structured data format (XML light)
Perfect for storing data in the browser for offline use
No comprehensive support for JSON is Oracle
Should see something in the future
Consider PL/JSON till then
Or for basic JSON object support try:
46
apex_util.json_from_sql(
'SELECT ename , empno, job ' ||
'FROM emp ' ||
'ORDER BY ename'
);
![Page 47: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/47.jpg)
Overcoming LS “strings only”
Local storage stores simple key/value strings
We need to convert JSON when using it with local storage
JSON.stringify
Turns a JSON object into a string equivalent
Can be used going into local storage
JSON.parse
Turns the string back into an object
Can be used going out of local storage
47
![Page 48: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/48.jpg)
Storing JSON in LS
JavaScript added to app
48
ONLINE
WHEN sync button clicked
call ajax process
store json output as string in ls
END WHEN
![Page 49: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/49.jpg)
Accessing JSON in LS
JavaScript added to app
49
OFFLINE
WHEN emps page loaded
parse json string to get object
loop over emps to build emps list
END WHEN
WHEN emp selected from emps page
parse json string to get object
init emp details page with values
transition to emp details page
END WHEN
![Page 50: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/50.jpg)
Updating JSON in LS
JavaScript added to app
50
OFFLINE
WHEN existing emp modified
parse json string to get object
update existing emp with new values
stringify json object and store in ls
END WHEN
WHEN new emp created
parse json string to get object
add new emp with new values
stringify json object and store in ls
END WHEN
![Page 51: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/51.jpg)
Demo
Manipulating data offline
51
![Page 52: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/52.jpg)
Part 5:
Syncing data when online
52
![Page 53: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/53.jpg)
Caution: Lost updates ahead
Data in LS must eventually be synced with the DB
Be careful if users can modify the same data as
others while offline
Lost update detection/handling is almost always custom
Best to avoid it all together if possible
53
![Page 54: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/54.jpg)
Showing that updates are ready
JavaScript added to app
54
ONLINE
WHEN home page loaded
parse json string to get object
count modified and new emps
add count bubble to sync button
END WHEN
![Page 55: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/55.jpg)
Pushing updates to server
JavaScript/Ajax proc added to app
55
ONLINE
WHEN sync button clicked
parse json string to get object
loop over emps to build delimited string
pass string to ajax process
END WHEN
WHEN ajax process called
parse delimited string to array of emps
loop over emps
parse emp string to array of attrs
update emp with new values
emit updated json object
END WHEN
![Page 56: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/56.jpg)
Demo
Syncing data online
56
![Page 57: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/57.jpg)
Gotchas
Always use full paths to access files offline
Fallback keeps online path
Clear standard cache when needed
Use version parameter
Web developer
57
![Page 58: APEX Unplugged Building Oracle Application Express ...€¦ · APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior](https://reader036.fdocuments.us/reader036/viewer/2022071605/6141ace8d64cc55ff075524b/html5/thumbnails/58.jpg)
Hopes, next steps & questions
I’d like to see built-in support for offline in APEX
Would start with clean(er) URLs
Eventually lead to declarative options/capabilities
Next steps
Try the demo app
Learn more
http://www.html5rocks.com/en/tutorials/appcache/beginner/
Any questions???
58