Someone recently asked me about the difference between an APEX page item’s
Default attributes. I’ve always been confused about these options so I decided to further investigate them. This post will cover the differences between Source and Default along with some additional info.
Page items can be set in different ways and there is an order of operations to which “setting” takes precedence:
- Session State: What ever is in session state will always trump the page item’s Source or Default settings*
- Source: Source comes next. For most people this is
Database Column(if using
Automatic Row Fetch)
- Default: If the page item is still null then Default will be used. This attribute doesn’t have as many options as Source (just
PL/SQL Expression, and
PL/SQL Function Body)
* The Source attribute has an option to ignore the current session state value.
Neither Source or Default saves the value to session state*. Instead it is what is shown on screen. If Source or Default is used the value will only be saved to session state once the page is submitted.
* Read below as the value is temporarily used in session state for the remaining duration of the page load.
I think a lot of the confusion with Source and Default is that in some cases Default is redundant and unnecessary. I think Default is only required when the Source is set to
Preference. For the other options (see below) you can wrap the returned value with a
Source has additional attribute that Default does not:
used option is set to
Always, replacing any existing value in session state this means that after the page has loaded the value in Session State may have a value that is different than the value that is shown on the screen. The following image shows the result of this situation (i.e. different session state vs on screen value).
Suppose that a
Before Header computation exists and sets
P1_DEMO to a static value:
From Computation. This means that during page load, right after the computation is run, the session state value for
P1_DEMO Source is set to
From Source and
Always, replacing any existing value in session state is used. After
P1_DEMO is “loaded” during the page load computation, the session state of
From Source for the duration of the page load. After the page is loaded the session state value is
From Computation. The following image highlights this. For both the
After display only items the Source was set to
This can cause some weird behaviors on a page that has AJAX calls. The value in session state changes during the page load process. After the page is loaded it may flip flop and the AJAX call could use the “old” session state value (see screen shot above).