8.5.6 Application Items

An application item is a named value holder that persists for the duration of the user session.

You define them in Shared Components > Application Items. A typical use case is a USER_ID item storing the numerical id of the currently logged-in user.

Many enterprise apps have some form of a USERS table storing the username, email address and other information about users. Other tables in the app data model reference the ID primary key of this USERS table. However, users authenticate to the application using their username. To avoid having to lookup the ID value from the USERS table using the logged-in username over and over throughout the app, define a USER_ID application item and lookup its value at login time. Then any page in the application can reference the application item's value using #USER_ID#, &USER_ID., or :USER_ID depending on the context.

The application item is the value holder. To compute its value after the user authenticates, use a companion application computation shared component. As shown below, the app computation references the USER_ID app item name, chooses a Computation Point of After Authentication, and sets a value using one of various supported approaches. Here a SQL query computes the value by referencing the :APP_USER bind variable that provides the logged-in username:

select id
  from users
 where username = lower(:APP_USER)

Figure 8-27 App Computation Sets the Value of App Item After Authentication



Any SQL or PL/SQL throughout your app can reference the value of an application item using an :ITEM_NAME bind variable and PL/SQL code you write in a page can assign a new value to it. To assign a new value from PL/SQL functions or procedures, use the SET_VALUE procedure in the APEX_SESSION_STATE package.