+ All Categories
Home > Documents > APEX Unplugged Building Oracle Application Express...

APEX Unplugged Building Oracle Application Express...

Date post: 16-Mar-2020
Category:
Upload: others
View: 2 times
Download: 0 times
Share this document with a friend
59
APEX Unplugged Building Oracle Application Express Applications That Can Survive Without the Internet Dan McGhan Senior Technical Consultant 1
Transcript
Page 1: APEX Unplugged Building Oracle Application Express ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

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 ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

My background

Dan McGhan

Senior consultant with Enkitec

Joined in March 2013

[email protected]

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 ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

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 ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express
Page 5: APEX Unplugged Building Oracle Application Express ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express
Page 6: APEX Unplugged Building Oracle Application Express ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

Cache Manifest

On/Offline Events

Local Storage

New tools

6

Page 7: APEX Unplugged Building Oracle Application Express ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

Cache Manifest

On/Offline Events

Local Storage

New tools with 2 apps

7

Page 8: APEX Unplugged Building Oracle Application Express ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express
Page 9: APEX Unplugged Building Oracle Application Express ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express
Page 10: APEX Unplugged Building Oracle Application Express ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express
Page 11: APEX Unplugged Building Oracle Application Express ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express
Page 12: APEX Unplugged Building Oracle Application Express ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

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 ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

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 ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

Part 1:

Creating the base applications

14

Page 15: APEX Unplugged Building Oracle Application Express ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

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 ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

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 ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

Part 2:

Making the JQM app offline(able)

17

Page 18: APEX Unplugged Building Oracle Application Express ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

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 ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

Adding the MIME type to glassfish

Modify default-web.xml

GLASSFISH_HOME\domains\domain1\config

19

Page 20: APEX Unplugged Building Oracle Application Express ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

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 ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

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 ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

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 ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

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 ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

Chrome and the cache manifest

Developer tools

24

Page 25: APEX Unplugged Building Oracle Application Express ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

Chrome and the cache manifest

AppCache Internals

25

Page 26: APEX Unplugged Building Oracle Application Express ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

Demo

Going offline

Added cache manifest

Pointed index.html to cache manifest

26

Page 27: APEX Unplugged Building Oracle Application Express ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

Part 3:

Transitioning between on/offline

27

Page 28: APEX Unplugged Building Oracle Application Express ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

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 ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

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 ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

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 ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

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 ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

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 ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

Saving APEX session in LS

Use local storage to save session id

33

Page 34: APEX Unplugged Building Oracle Application Express ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

Chrome and local storage

Developer tools

34

Page 35: APEX Unplugged Building Oracle Application Express ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

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 ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

Demo

Handling user explicitly going offline or online

36

Page 37: APEX Unplugged Building Oracle Application Express ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

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 ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

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 ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

Demo

Handling failed Ajax requests

39

Page 40: APEX Unplugged Building Oracle Application Express ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

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 ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

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 ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

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 ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

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 ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

Demo

Handling offline app updates

44

Page 45: APEX Unplugged Building Oracle Application Express ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

Part 4:

Working with JSON & Local Storage

45

Page 46: APEX Unplugged Building Oracle Application Express ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

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 ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

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 ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

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 ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

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 ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

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 ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

Demo

Manipulating data offline

51

Page 52: APEX Unplugged Building Oracle Application Express ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

Part 5:

Syncing data when online

52

Page 53: APEX Unplugged Building Oracle Application Express ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

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 ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

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 ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

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 ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

Demo

Syncing data online

56

Page 57: APEX Unplugged Building Oracle Application Express ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

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 ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

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

Page 59: APEX Unplugged Building Oracle Application Express ...nyoug.org/Presentations/2013/Winter/McGhan-NYOUG-2013-APEX-Unplugged.pdf · APEX Unplugged Building Oracle Application Express

http://www.enkitec.com

59


Recommended