Using Built-in Substitution Strings Tutorial – Part 2
Part one of this tutorial demonstrated the use of the apex_application API. This second part will build on this to look at other substitution strings that are available and how they can be used. The exercise below will create a simple “About” page that can be used for any APEX application. It is assumed that you have a workspace with the Sample Application installed as we will be building upon this application and it’s data structure.
The purpose of this tutorial is not to provide a list of substitution strings with their definitions, this can be found in the Oracle APEX help pages. These provide an easy reference to the different built-in substitution strings and the different ways they can be accessed.
Exercise 2 – Navigating back to the previous page
For this exercise we want to add an “About” page to the application that can be accessed from the Navigation Bar and returns the user back to the page they were previously on.
In the Application Builder:
- Select the Sample Application and click Create Page.
- Leave Blank Page selected and click Next.
- Give the page a name of “About”, do not use Breadcrumbs or Tabs and click through the wizard to Finish and create this page.
- Now click Edit Page and click to add a Region to this page.
- Click Next twice, accepting the Region is a normal HTML region, and set the name to be “About” and click Create.
- Now click to add a button to this Region.
- Click Next twice, confirming the button will be added to the About region and that you want to “Create a button in a region position.”
- Give the button a name and label of “OK” and click Next.
- Now click Next to navigate through the wizard, accepting all the default options, and finally select Create Button when available.
- Click to add a new item to this region.
- Click Next twice to create a Text item (note: in a real application you would create a hidden item instead).
- Set the item name to be P22_RETURN_PAGE, assuming your page is 22, and click Next to navigate through the wizard and create the Item.
- Now that you have an item to hold your returning page and a button to navigate back, you need to create a Branch. So click to create a new Branch.
- Click Next, then set the Page to be &P22_RETURN_PAGE. It’s very important that you remember the leading ampersand and the trailing full stop!
- Set the When Button Pressed field to be the OK button you’ve just created.
- Click the plus icon in the Navigation Bar region on your page to create a new entry in the Navigation Bar of your application.
- Set the Text to “About” and click Next.
- Set the page to be “22″, set Set these items to be P22_RETURN_PAGE and in the With these values type &APP_PAGE_ID.
- Now navigate back to your application and click Run Application, rather than running page 22.
- You should see an About link in your navigation bar. If you click this the Return Page field will display the page you were just on and the OK button will take you back to that page.
This exercise uses a couple of useful pieces of functionality. Firstly, the use of &P22_RETURN_PAGE. in the branch allows the branch on the page to be dynamic. Secondly, the use of the APP_PAGE_ID substitution string in the Navigation Bar link. This substitution string holds the page number that you are currently on and allows us to tell the About page where we want to return to.