Monday, 22 June 2015

Single Page Application with Oracle Apex

This post is the summary of a presentation held at KScope 2015. You will find links at the bottom to download the presentation and the example application containing all the code.

When using a web application on a smartphone a slow network can be really annoying. Especially moving to another web page can take more than a few seconds.
In mobile development often Single Page Applications are the answer to speed up the application. Because the whole application is on one page the only requests to the server are for getting data or submitting transactions.

Because my Apex smartphone application performed badly I wanted to convert it to a Single Page Application. As this is not supported by Apex the actions needed had to be coded manually in PL/SQL and JavaScript.

The Apex architecture relies strongly on page refreshes. Most of the processing is done when rendering the page or when submitting a page. All this processing can not be used in a SPA because it is rendered only once and never submitted (the Apex way). The image below shows which part of the Apex functionality is available.

There Dynamic Actions come to the rescue. They enable us to execute PL/SQL from an Apex page without having to code all the plumbing underneath ( JavaScript / Ajax / Serverside actions ).

So the way to go is to:
- create one page with all the regions we want on it
- disable all fetch processes
- replace page links with Javascript calls
- implement transactions with Dynamic Actions
- using JavaScript to handle (error)messages

The sample application contains some generic JavaScript functions for region management and messaging. On top of these functions for each region a set of specific JavaScript functions is built.

Much if not all of the code written could be generated from the Apex repository. It is possible to replace the manually coded PL/SQL performing the transactions by generic code based on the Apex repository. Also validations could be combined with this code. All the page links can be replaced by JavaScript calls. The messaging framework is already provided.

I think this way it is possible to generically create Single Page Applications with Apex, without all the manual coding described in the presentation. Only, I have not got the time to code it. Besides, it would be better if it were built into Apex, wouldn't it? Then everybody could benefit. Well Apex team, what about another challenge?

More information about the exact implementation is available in the presentation : SPA with Oracle Apex You can also download the example application ( Apex 5, only the EMP table needed ) :
Be sure to check the supported objects when importing because the application depends on a package spa_pck.sql. 

Happy Apexing,
Dick Dral