Thursday, 24 July 2008

Ajax and Improved help text (or the wasted life of Mungo Park)

Studying history in a Nigerian school was, sometimes, like having a conversation with a schizophrenic. They teach you African history from the European perspective - and then they teach you, well, the truth. I remember our teacher (hello, Mr Dumatonu) teaching us how Mungo Park discovered the river Niger in the 18th Century; and then I remember him returning to class the next day to tell us how, in truth, the Africans had discovered it millennia before that.

Sometimes studying Apex I feel a little like old Mungo Park discovering paths that many have walked down as if they're new. (It's kinda like Neil Armstrong landing on the moon and discovering a KFC.) Yesterday, for instance, a colleague commented that the popup windows that, er, pop up when you click on an Optional Label with Help link are terribly ugly. He was right, and so I spent today investigating ways to rewrite it. (I've been messing with about with my templates a lot of recent; perhaps I'd be better off making a copy of the whole theme so I don't do any irreparable damage?)

I've had to travel down many strange paths and some that are only half-familiar: the first thing I did was create a CSS div class which I put in an After Header region on my Page Zero. Whilst there I created an HTML region, inside which I created a div and applied the class I'd just created. My plan was to hide my div and use it to display help text when needed.

Next I wrote an application process which would take an item_id and return the appropriate HELP_TEXT from APEX_APPLICATION_PAGE_ITEMS (by the way, does anyone know if item_ids are unique or do I have to qualify my query by app_id and page_id too?).

And finally (and this is the bit I really enjoyed) I wrote some javascript (which I fired from the anchor tag of my label template) which contained some Ajax that executed my application process (to get my help-text). Next it was a simple task to place that text inside my div, position it on my page and set it to visible. (I created a timer to keep it visible for 5 seconds, which should be long enough for the slowest of readers.)

The Ajax I had to learn today. To call an application process is really easy. You create a new htmldb_get object (var lookAtMeMum = new htmlb_get(null,&APP_ID.,'APPLICATION_PROCESS=myApplicationProcess',0);). You can pass values into your application process - in my case I wanted to pass in the item_id: (lookAtMeMum.add('F_ITEM_ID',itemValue);). And finally, you get the value returned from your application process (you'll need to add a htp.prn(returnValue); in your process to send a value back).

Easy-peasy. When you know how. (It took me all of today to figure it out.)

Oh, one difference between Mungo Park and I. He died on the river Niger. I intend to die on the breast of a beautiful, leggy blonde.

Just watch.

1 comment:

Patrick Wolf said...

David,

you just need the item-id for your query, in the underlying table it's the primary key.

Patrick