By | 11 May 2011

Stop Using Page Activate PeopleCode

I think the Page Activate PeopleCode event is evil. There are many delivered components from Oracle that actually use this event to do extensive processing and to load buffer data. So I see developers mimic this and use it in their code structure. Generally, when I see people use this event they just need some piece of code to fire once before the user sees the page and after all the buffer data has loaded. The Page Activate event does indeed accomplish this goal but there is a better way.

Using the Page Activate event for buffer loading and manipulation works when you have one page in the component. What happens when later someone decided to add another page to the component? This can cause some serious issues if you are doing buffer manipulation. The reason is that every time the user tabs between pages in the component, the page activate event fires. This could result in data loss if you are flushing component buffers and reloading every time the user looks at the page and the user may not even know they lost their data. Additionally, you are causing unneeded database processing because there is no need to reload the buffer when the user flips between pages.

Another important issues is that the Page Activate event does not trigger when the component is being invoked via a Component Interface. So if you think there is ever a time where you will need to load data into the Component with a CI you should not even put any core logic in the page activate event.

So what should you use instead?

Most of the time you should put your code in the Component PostBuild event. This event fires once for the component and towards the very end after all the data has been loaded into the buffer. This is a great place to hide fields, pull data from the database, disable fields, etc.

Most of the code that I see people put in the Page Activate event will actually be better served in the Component PostBuild event.

Exceptions

One exceptions where you may want to use Page Activate PeopleCode is if you have a few pages in the component and one of those pages is rarely viewed and the data on that page is “expensive” in cpu terms to load or calculate. In this case you could put that complex code in Page Activate so it only fires when a user wants to look at that data. This could also be done using a push button on the page with some warning about “please be patient while we load the expensive data.”

Do you want to become a CI Expert?

If you want to learn more about developing using Component Interface then check out our CI Training Video.