0
votes

In my apex app, I have an array I want to store as an application item. When I try to do this like (APP_ITEM_ARRAY is an "application item"):

declare
TYPE array_t IS TABLE OF VARCHAR2(255);
lv_arr array_t;
begin

:APP_ITEM_ARRAY := lv_arr;

end;

I get an error (expression is wrong type). So for now I'm testing using an apex_collection, which seems usable on my pages. But I'm a little unsure, are these part of the users session?

How best to store (pl/sql) arrays in session state for Apex to use across pages?

In my use case, the array is actually a list of groups the logged in user is in...so I also need an easy way to determine whether the user is in a group, or not, ala some kind of "exists" or "member of" and then on my pages I'll use that...show hide Buttons, Nav Items, etc.

1

1 Answers

1
votes

In apex, a page item is always a string under the hood, so it's not possible to a value of a complex datatype to it (and it explains the error too). It's possible to use collections too but that would be overkill for this kind of functionality. To store multiple values in a single page item (for example for items of type checkbox - where you can select multiple values - or like in your case), a colon-delimited string is used. There is a pl/sql API APEX_STRING that has functions and procedures to convert an object of type apex_t_varchar2 (which is basically an array) to a string and back.

Example:

DECLARE
  l_groups apex_t_varchar2;
BEGIN
  l_groups := apex_t_varchar2('user','administrator','manager');
  :P1_PAGE_ITEM := apex_string.join(l_string1);
END;
/

Side remark: what I just explained answers your question, but why would you store that information a page item ? Just leave it in the database and when you need to know if a user is in a group, just use a database function. Or better, use an authorization scheme to determine what functionality is available to a user based on the group he is in - that is what those are made for.