Pages

Thursday, 22 September 2011

Apex Tutorial: Adding a Read Only Option

Last week Recently I published a tutorial walking through setting up a form and report on the same Apex page. This one done using out of the box functionality, without the use of dynamic actions. Hence this is aimed at those learning the Oracle Application Express development tool.

Edit Feb 2012 :
Bug 13587192 Quick picks are displayed for read-only page items and in Printer Friendly mode
Has been included in the 4.1.1 patchDemo; OTN Forum entry.

We can take this a step further and extend this functionality to open the record in read-only mode first.

1) Modify report link to pass P6_MODE = R, instead of E
Now we have three "modes" View (which doesn't display the HTML region), Read only & Edit.

2) Modify all form items to apply read only condition to P6_MODE = R
Now when you click the link for an employee record, the form initially opens in read-only mode.

3) Modify HMTL region condition to be :P6_MODE IN ('E','R')
We need this region to display in edit and read-only mode.

4) Extend Delete/Save buttons conditions to include :P6_MODE = 'E'
ie => :P6_EMPNO IS NOT NULL AND :P6_MODE = 'E'
We don't necessarily want these buttons being displayed in read only mode. 

5) Create Edit button in the HTML region
You could add an authorisation condition on this button to make editing records available only to privileged users.
* condition :P6_MODE = 'R'
* redirect to page 6 
* passing parameter P6_MODE = E

The problem now if if you have, for example, quick picks on any of your items - these will still be displayed as the read only option only adds the class="display_only" tag to the item definition:
6) So to clean this up, we need to make a copy of item P6_JOB
Use nearby sequence number to create the copy in the same position on the page.
My job field sequence was 30, so I chose 35
7) Remove the quick picks option from copied item P6_JOB_DSP
These are the options we don't want displayed in read-only mode. The user can't save the change, but it looks untidy.

8) Add display condition on P6_JOB_DSP as :P6_MODE = 'R', retaining the existing read only condition.
Alternatively we could set the item type to display only, however we still only want it appearing in read-only mode.
9) Add display condition to P6_JOB as :P6_MODE = 'E'
The original item only needs to appear in edit mode.

We now have a functioning read-only mode option, with an Edit button available to re-open the page in edit mode.
The item list in the page builder will now look more like this:

Run the demo to see it in action.
There are other techniques demonstrated on this page.

I hope that further helps your understanding of some of the concepts available to the Application Express environment.

Scott.

1 comment:

  1. "last week" huh?

    I don't know whether it was google ignoring my schedule setting, or this frustratingly tenuous data connection I have at Brisbane airport.

    Either way, this phone is moments away from learning to fly...

    ReplyDelete