Wednesday, 13 October 2010

Oracle Portal Session Variables

Because of the way Oracle portlets work with Oracle Portal you can't use standard PL/SQL package session variables.

Instead you need to use the built in Portal session API wwsto_api_session.

Firstly declare a variable to act as an object to store the session data in.
l_store portal30.wwsto_api_session;
Then load your session, if it doesn't exist yet it will get created. Domain and subdomain do not have anything to do with web addresses but instead would be better described as a unique reference, I would define the domain as the application and the subdomain as a page within the application.
l_store := portal30.wwsto_api_session.load_session ('DOMAIN', 'SUBDOMAIN');
Then you probably want to save some data to your session, you do this by defining a attribute name and value in set attribute.
l_store.set_attribute ('NAME', 'VALUE');
If you want to grab a variable that has been set then you would use get_attribute_as_varchar2, there are also date and number variations of this API function.
my_var := l_store.get_attribute_as_date ('NAME')
If you've set any attribute variables then you need to make sure you save your session
l_store.save_session;
The session and session variables will automatically get dropped when you log out of Portal or close down your browser, you can manually drop the session with.

wwsto_api_session.drop_session('DOMAIN','SUBDOMAIN');
Finally if you want to grab your session id you can use.
wwctx_api.get_sessionid

No comments: