McRivers
McRivers

Reputation: 373

Setting Session State - APEX 21.1

Based on the documentation and examples I have come across, it seems that the way to set/pass session state between pages is via the URL. It got me thinking, is it ok to reference page items from a different page directly? Or are there downsides in doing this that someone new to APEX (like me) may not be aware of initially.

For example:

Are there any reasons to not set up a BEFORE HEADER Computation on PAGE 2 that sets P2_SOME_VALUE = :P1_SOME_VALUE? (Assuming that P1_SOME_VALUE is a given to always be available in the session for PAGE 2)

If going from PAGE 1 to PAGE 2 is done using a hyperlink, then I understand it is easier to set the session state using the REDIRECT URL attribute method that I have seen. I have come across a situation in my app where a URL is generated dynamically after a chain of dynamic actions and using the BEFORE HEADER Computation seems like the cleaner/simpler solution for my given situation. Just want to make sure I am not overlooking anything.

Upvotes: 1

Views: 1026

Answers (1)

Koen Lostrie
Koen Lostrie

Reputation: 18665

The behaviour you describe, using a pl/sql process which references a page item from another page will work fine, but there are some things to take into account. Not sure if this list is exhaustive, others might comment:

  • Personally I try to avoid references to items on other pages within a page, because that makes developing harder - when working on page x, you'll usually search for item occurences within page only . If there are occurences on other pages the application becomes less clean. I try to follow this as a best practice. The cleaner the app, the easier to maintain. When you have to work in this app 2 years from now, you won't remember that P1_SOME_VALUE is referenced on page 2. Or that other developer who works on it will hate you forever ;)
  • This can possibly make debugging a lot harder. Suppose page is accessed via a url or branch that has the option "clear cache for pages" set to "page 1", then the value of P1_SOME_VALUE will be cleared because that item is defined on page 1. Debugging this issue will be a challenge.
  • Passing a value in a url is very secure. If you use checksums, there is no way for a user to manipulate the value of the page item manually.
  • Note that the DOM of the page only contains the page items that are defined on that page. This implies that you cannot use javascript on page 2 that references P1_SOME_VALUE or set the value of P1_SOME_VALUE using javascript on page 2. This doesn't matter in your use case.

An alternative to referencing page items in another page than the page they belong to is storing the data in a collection - that will exist for the duration of the session.

Upvotes: 2

Related Questions