jApex – A jQuery Plugin for APEX
Posted by Tyler Muth on August 19, 2009
In a previous post I proclaimed that jQuery Selectors Will Change Your Life. While working on an AJAX centric APEX project, I wanted to use jQuery selectors to post data from an APEX page to an application process so I wrote a jQuery plugin. Over the course of this project the plugin has grown into something that I think the community would find useful. Essentially it serves the same purpose as Carl Backstrom’s htmldb_get() function, but adds the power of jQuery selectors. Carl was actually the one that introduced me to jQuery, and I’m sure he would have written something similar, only much better and in half the time.
I think the best way to introduce it is with a few quick examples. I have a full set of working examples on apex.oracle.com here, but lets start with some simple examples to give you an idea of how it works.
APEX Items
The following code sends every item on an APEX page to the application process “SOME_APP_PROCESS”. It will then popup an alert with the results from the application process. Note that we did not have to specify each item individually, the jQuery selector (documented here) grabs them all.
var options = {
appProcess: 'SOME_APP_PROCESS',
pageItems: $(':input'),
success:
function(data){
alert(data);
}
};
$.jApex.ajax(options);
If we want to send all items inside a div with ID “employeeDiv” and send the results to the Firebug console:
var options = {
appProcess: 'SOME_APP_PROCESS',
pageItems: $('#employeeDiv :input'),
success:
function(data){
console.log(data);
}
};
$.jApex.ajax(options);
Want to send the items P1_NAME, P1_EMAIL, P1_PHONE?
var options = {
appProcess: 'SOME_APP_PROCESS',
pageItems: $('#P1_NAME, #P1_EMAIL, #P1_PHONE'),
success:
function(data){
console.log(data);
}
};
$.jApex.ajax(options);
Other Features
- You can also send data to the x01-x10 parameters. There are several examples of this in my sample app.
- I had already written code to support sending arrays to the f01-f50 parameters used by Tabular Forms. I really don’t like Tabular Forms and rarely, if ever use them. However, I figured someone would want / request this functionality so I enhanced it a bit to better support Tabular Forms. Keep in mind this functionality has not been tested much, so use at your own risk.
Tips
- $ is the alias for jQuery
- jQuery plugins almost always have 1 parameter that is object. Each property of the object is analogous to a traditional JavaScript (or for that matter PL/SQL) parameter.
- Parameters can be objects, arrays, scalars or even functions. Most people are used to scalars, so passing a function in as parameter / property can really be confusing at first.
Download
You can download the jQuery plugin and the example APEX application here.
John Scott said
Tyler,
You’ve been reading my mind, I’ve been thinking about doing something similar for a while (actually it was while I was explaining the htmldb_Get to someone else, when I thought that it would make sense to make a jQuery plugin to remove some of the APEX-specificness of it).
Fantastic job!
John.
Louis-Guillaume Carrier-Bédard said
Hi Tyler,
Mind if I put the plugin on apexquebec.com in the jquery plugins section ?
I’ll translate the website in a few weeks.
Have a nice day,
Louis-Guillaume
Mark Lancaster said
Hi Tyler
I’ve deliberately restricted myself to just using the p_widget* and x01 – x10 variables for AJAX.
Carl had indicated it was safe to use these without fear of side effects.
Are you saying it’s equally safe to the other parameters in the wwv_flow.show procedure?
The web-sheets demo I saw at OpenWorld last year was using cell based AJAX processing.
Your implying it’s fine to do table-based AJAX processing.
Very interested to hear your response on this.
Peter Raganitsch said
Hi Tyler,
this looks very promising, looking forward to actual give it a try.
Peter
Justin Patterson said
Tyler,
Thanks for this great example, I first started using JQuery after your initial posting pointed me to it. I’ve learned to try and leverage as much as I can on JQuery rather than rewriting what has already been developed. This is just another example of why you should use it.
Thanks again,
Justin
Patrick Wolf said
Hi Tyler,
really cool! I’m sure we will grab some code and ideas from your plug-in for enhanced AJAX support in 4.0.
Regards
Patrick
jApex – A jQuery Plugin for APEX | Oracle said
[...] Link to the original site Tags: Ajax, Apex, Apex Project, Application Process, ORACLE BLOGS, Selectors [...]
jQuery Anything Slider Plugin | Benzing Technologies | Creative Web Design, Affordable Web Hosting, SEO, Social Media Marketing said
[...] jApex – A jQuery Plugin for APEX « Tyler Muth's Blog [...]
Tracking outgoing links with Google Analytics and jQuery « Benzing Technologies said
[...] jApex – A jQuery Plugin for APEX « Tyler Muth's Blog [...]
jQuery Anything Slider Plugin | Benzing Technologies said
[...] jApex – A jQuery Plugin for APEX « Tyler Muth's Blog [...]