Wednesday, 20 March 2019

Oracle APEX - be careful not to duplicate APEX_ITEM ID for different items

When page gets complicated and there are a lot of regions, it is easy to forget which items created with APEX_ITEM package have which ID.

This IDs is later used in page processes and are referenced as APEX_APPLICATION.G_Fxx collections (where xx is ID defined in APEX_ITEM funtions call).


For example, if we have two SELECT statements as source for two different regions on page

SELECT
    level as nivo,
    apex_item.checkbox(1, level) as nivo_input
FROM dual
CONNECT BY level <= 10;

SELECT
    level + 30 as nivo,
    apex_item.text(1, level + 30) as nivo_input
FROM dual
CONNECT BY level <= 10;



There will be no error when page is generated and shown. Items are working as they are supposed to. You can mark checkboxes from first region and enter/alter values in second region.


BUT!!!!


If we have after submit process which loops through collection APEX_APPLICATION.G_F01 and do some work... we encounter a problem. LOOP takes data from both items and do the operation in process (deletes rows).

Example of process:

APEX_DEBUG.ENABLE;

FOR t IN 1 .. apex_application.g_f01.count LOOP
    apex_debug.message('how many: ' || apex_application.g_f01.count);
END LOOP;



Debug after processing:


We can see that process combined values from 2 items.

No comments:

Post a Comment