Friday, 19 February 2010

Static Region Id's and Ajax Fun

More Online Store demo shenanigans for you. A bit dry this one I'm afraid.

A couple of days back I decided to export/import my Online Store demo, and whilst viewing the new imported version of the application found it to be completely kaput.  It didn't take long to realise that I had made the mistake of hard coding region id's in some of the Javascript.  Well, I thought this will be easy to fix as I can just utilise Static id's instead in my regions and in place of #REGION_ID# in templates.  So far, so good, but then I realised that the Ajax refreshing of the Products and Shopping Basket regions is done using calls to html_PPR_Report_Page and $a_report, and both these require the internal numeric region id as a parameter.  As far as I know neither recognises the Static id (please correct me if I am wrong).  Doh!

I get around this by creating hidden items (i.e. P1_PRODUCT_REGION_ID) based on a SQL query that uses the Static id to get the 'real' internal numeric ID. The following SQL does the job:

SELECT region_id
FROM   apex_application_page_regions
WHERE  static_id      = 'PRODUCTS_REP_REG'
AND    page_id        = v('APP_PAGE_ID')
AND    application_id = v('APP_ID');


All well and good I thought, but then I found another issue.  In the main Products region if the search is refined so that no rows are returned then instead of displaying the 'When No Data Found Message' wording from Report Attributes section it displayed the whole page embedded within the region.  Double Doh!

Again, it appears I had hard coded the internal region id into the 'When No Data Found Message' section, something like:

- No Products Found -

This had worked nicely in the orginal app from which the export came, as in lieu of a 'No Data Found' template, I simply copied the div and table tags that would appear if rows were returned in the Products region. But now it was useless. Therefore, I employed the following instead to fix the problem:
- No Products Found -

This simply embeds the value of the P1_PRODUCT_REGION_ID (the internal id of the product region) into the HTML. Voila. It works a treat, and no hard coding of id's in sight.

So, not a lot of visible progress on the store this week. Although, I have managed to make the site look similar and work the same way in IE, FF and Chrome.

Hopefully next week I can start to look at improving the look of the store. I also want to change the templates to be Div based as per the new Apex 4.0 theme.

2 comments:

Patrick Wolf said...

Hi Paul,

a quick tip. Always use bind variables in your SQL statement instead of the V function. Because that can have cause performance problems. Have a look at http://www.inside-oracle-apex.com/drop-in-replacement-for-v-and-nv-function/ for details.

Regards
Patrick

Paul Brookes said...

Thanks Patrick,

Good point!

Now updated to use bind variables instead.

Cheers,

Paul.