Posts Tagged ‘apex’

ApEx Select list with Redirect confirm change

Thursday, July 17th, 2008

We recently had a situation that required a little bit of head scratching.  We had a page with a Select List with Redirect that was used to populate some form fields based on the contents of the Select List.  The users could change the values in the form and save them, but if they changed the Select List before using the ‘Save’ button then the changes would be lost.  What we wanted to do was add a confirmation message to make sure the user saved the details before changing the Select List.

Unfortunately you can’t put an ‘onchange’ handler in the HTML Form Element Attributes as ApEx is using onchange to do the redirect. Any code we put in is simply ignored.

Instead, we need to mimic what ApEx does, and then put in our code.  Firstly define some JavaScript in the page header :

<script type="Text/JavaScript">
var startVal = &P68_PERSON_ID.;
function checkSave(p) {
    if (confirm('Have you saved details for this person?')) {
       location.href='f?p=&APP_ID.:68:&SESSION.::NO::P68_PERSON_ID:'+
                  p.options[p.selectedIndex].value;
    } else {
       for (i=0;i<p.options.length;i++) {
          if (p.options[i].value == startVal) {
             p.options[i].selected = true;
          } else {
             p.options[i].selected = false;
          }
       }
    }
}
</script> 

This code is from page ‘68′ in our application, and the Select List is called P68_PERSON_ID.   You’ll need to change these to something appropriate for your app. 

The JavaScript saves the initial value set when the page loads here :

var startVal = &P68_PERSON_ID.;

If the user confirms they have saved the details, then the window’s location is changed and the selected item used as a basis for the new page.  If the user cancels we need to reset the selected item back, as by now the browser has changed it for us (thanks!).

Next, change the Select List with Redirect to just a normal Select List, then, add an onchange handler to the the Form Element Attributes to call the JavaScript :

Now, when the user changes the value in the list box they get prompted to check they have saved the details, which prevents them changing the page data inadvertently.

Using Ajax to populate one field based on another in an ApEx form

Friday, June 20th, 2008

Often it can be useful to populate one field on a form based on the content of another in a live and dynamic fashion. Luckily this is easily achieved using the Javascript API supplied as part of ApEx 3.1.

This post illustrates an example where we wanted to lookup a value (called IMD Rank) based on the Postcode entered in another field. Users can either enter it manually, or click on a ‘Lookup’ button next to the field.

Firstly, define your process that will calculate the required value. This is most easily achieved by creating an Application Process (under Shared Components) which will run ‘on demand’.

This PL/SQL is just retrieving a value (RANKOFIMD) from a table based on a page item (P27_P9_POSTCODE). Note the ‘htp.prn()’ function call which will actually ’send’ the result to our page.

Next, define the JavaScript required to execute the process and return a value.  We’ll be displaying the returned value in the page item called P27_P16_IMDRANK. Add this script to the HTML Header section of your page.

Note : it is OK to append this script to any code which may already be in this field.

Next, add a button to invoke the JavaScript. I just added a standard HTML button after the element :

Clicking on the Lookup button now populates the field based on the value retrieved by the GetIMD application process.

Editting ApEx theme images using Mac OS X and WebDAV on XE

Friday, June 6th, 2008

Recently we had to make a couple of minor tweaks to a couple of ApEx theme images stored in an XE installation.  At first we scratched heads a little but then found a helpful post on the ApEx forum which made it much easier.  All we needed to do was work out how to do this using Mac OS X Leopard.  Luckily, it’s also very easy!

Firstly open a Finder winder then choose Go -> Connect to Server from the Finder Menu :

Connect to Server

Enter the server name and port that the embedded HTTP gateway is listening on (8080 by default) and click on Connect.  You will then need a database user name that has permission to modify the ApEx schema (FLOWS_*).  A DBA user name or the FLOWS_* user name and password should work fine :

WebDAV File System Authentication

With this done, click OK and logon to the database. A new Finder window will then appear showing the ‘root’ of the database WebDAV file system :

You can now navigate through the tree to find the image in question by following through i -> themes -> theme X :

WebDAV theme path

I haven’t yet worked out how to edit the images ‘in place’ but it’s easy enough to copy the required images out to a folder on your hard disk, edit them, and then copy them back into the appropriate folder.

Change the background colour of an ApEx page

Wednesday, June 4th, 2008

The simplest way to change the background colour of an ApEx page is to edit the <body> template using the Application Builder.

Login to ApEx and navigate to your application.  Click on ‘Shared Components’, and then ‘Templates’ to view the templates for the current application theme.

ApEx templates

Navigate down to find the appropriate page template that you are using (tip: the ‘References’ column holds a count of the number of uses for a template, so if you’re not sure look for something greater than zero).  When you’ve found your template, click on it to edit the HTML elements of the template :

Edit template HTML header

Here you can see we’re using the ’style’ tag to set the background colour (using background-color) to the hex colour #46C6BA.  Standard HTML colour names such as ‘white’, ‘blue’ etc can also be used here.

New ApEx book published

Tuesday, June 3rd, 2008

We just spotted this new ApEx book on Amazon entitled “Pro Oracle Application Express” :

It’s not released yet but looks good, and is written by two giants of the ApEx scene, John Scott and Scott Spendolini, so we’ve placed our order already!