Read-only condition not working

I'm developing an Oracle Application express (APEX 4.2) application.

One of the page controls (text box, title) have a "PL/SQL Expression" read-only condition:
:APP_PROJECT_READ_ONLY = 'YES'

:APP_PROJECT_READ_ONLY is an application item and it's set from a dynamic action on_load which fires on page load:

DECLARE
  CURR_USER VARCHAR2(50);
BEGIN
  IF :REQUEST = 'NEW' THEN
    :APP_PROJECT_ID := 0;
    :APP_PROJECT_READ_ONLY := 'NO';
  ELSE
    :APP_PROJECT_ID := :P2_ID;
    SELECT OWNER  INTO CURR_USER 
    FROM PROJECTS
    WHERE ID = :APP_PROJECT_ID;
    IF CURR_USER = :APP_USER THEN
      :APP_PROJECT_READ_ONLY := 'NO';
    ELSE
      :APP_PROJECT_READ_ONLY := 'YES';
    END IF;
  END IF;
EXCEPTION WHEN NO_DATA_FOUND THEN
  NULL;
END;

Checking session state shows that :APP_PROJECT_READ_ONLY's value is correct, but it doesn't seem to drive whether title is read only:

How can I fix it?

Upvotes: 1

Views: 1406

Answers (1)

Scott
Scott

Reputation: 5055

Your problem is chronology. The page renders, conditions evaluated, then you calculate your application item on the browser's page load.

Move your code into a computation, perhaps before regions, hence done as part of page render.

REQUEST values are organically only available in page processing, so unless you're explicitly setting that, it may be something to look out for.

You should also consider using declarative actions, where possible.

www.grassroots-oracle.com/2013/05/performance-of-apex-conditions.html

Upvotes: 3

Related Questions