Ah, sunny Milton Keynes. There’s no place like it. Nestling in the heart of England, halfway between London and Birmingham, my home town has plenty to recommend it.
Yes, many of my countrymen like to poke fun at the Concrete Cows that are Milton Keynes’ most famous landmark. However, the one irrefutable benefit of living here, especially if you tend toward the geeky, is that Milton Keynes is also the home of the National Museum of Computing, hosted in Bletchley Park.
One thing about Milton Keynes is the interminable roundabouts throughout the city. Just keep turning left at every roundabout and you’ll be guaranteed to end up back where you started.
The same however, cannot be said of APEX – at least, not without a little bit of work.
In the example that follows, we have a page in an APEX application that can be invoked from a number other pages. The target page has a back button to return to the page you just came from. The question is, how do you make the target page re-direct back to the correct calling page ?
It must be said that the solution that follows can best be described as crude but effective. I’d be interested to hear if you come up with a more elegant solution.
Anyway, here goes….
The target page
I’ve created an application which has a single blank page called Welcome_MK. This will be the target page.
First of all, let’s put something on the page.
In the component view, in the Regions section, hit the Create Icon. BTW – just in case you’re wondering, the component view looks like this :
Now to create the target page :
From here, click Next.
In the next page, select HTML and click Next
The title is Welcome to MK. Click Next
In the HTML Region Source, enter what should be the city’s motto :
Welcome to Milton Keynes where all roads lead to….another roundabout
Click Create Region
Add a hidden item
Back in the Component View, we need to create a hidden item. This will hold the number of the page we’ve come from to get here :
In the Items section hit the create icon
In the Create Item dialog select an item type of Hidden.
Item Name will be PX_PREV_PAGE where ‘X’ is the number of the target page in your application. In my case it’s Page 1 so… P1_PREV_PAGE
For Region, select the Region you’ve just created ( in my case, Welcome to MK(1) 11).
Accept the default values and once again, Click Next
Source Used – set to Always, replacing any existing value in session state
Click Create Item
Create the Back button
Back in the Component View, go to the Button Section and hit the create icon
Select the same region for your button as the one you’ve just created your hidden item in.
Select Create button in a region position and Click Next
Button name is BACK
Label is the same
Click Create Button
Create the branch
Now for the “clever” bit. We’re going to create a Branch to dynamically re-direct to whatever page number is in the P1_PREV_PAGE hidden item.
In the Component View under Branches click the create icon.
Branch Point – On Submit : Before Computation( Before Computation, Validation, and Processing)
Branch Type – Branch to Page Identified by Item ( using Item Name)
Identify Item – the hidden item you just created
When Button Pressed – select the Back Button you created
Hit Create Branch
Now we’ve got the target page, we need a page to call it from…
The Calling Page
Click Create New Page
Select Page Type : Report
Select Interactive Report
I can’t think of a suitable page name so I’ll just accept the defaults and click Next
Nope – don’t want to use tabs – Next
Now for the select statement. Let’s keep it simple :
SELECT 'Turn Left' FROM dual;
Link to Single Row – No
Now we want to make the one column in the report a link to our target page….
In the component view under Regions, click on the Interactive Report link.
In the Column Attributes section, click on the Yellow Pencil icon to edit the TURNLEFT column.
Under the Column Link Section, select an appropriate icon for the Link Text. I decided on the magnifying glass.
Target is a Page in this Application and enter the Page number of the target page.
Item 1 – the Name is the name of the hidden column we created in the target page.
The value is the number of this page.
Hit Apply Changes
I realise that, at this point, Alan Turing is probably turning in his grave. The place that he made famous mentioned in the same breath as the callous and unthinking use of what he would call “magic numbers” ( that’s hard-coded values to anyone younger than me…which is probably most of you).
Time to give our quick ‘n’ dirty solution a test drive.
Start by running the report ….
Click on the magnifying glass icon (or whichever one you chose for your link) …
Now for the moment of truth…click the Back button.
Well, it does work. Like I say, it’s not the most elegant solution, but it’ll do for now.