Search
Categories

Entries in events (2)

Friday
06Nov2009

XPage Cheat Sheet #1 - The Page Lifecycle (Update)

A few weeks ago I wrote a blog outlining the XPage lifecycle.  It appears that with 8.5.1 there have been a few changes made.  The following is an updated account of the lifecycle.

This example is based upon a single XPage (X) with 2 custom controls (A & B). Controls seem to be processed in the order they are listed.

The following are executed ONCE only:-
X.beforePageLoad
A.beforePageLoad
A.afterPageLoad
B.beforePageLoad
B.afterpageLoad
X.afterPageLoad

The next set of events are ONLY executed when a Full or Partial refresh occurs:-
X.afterRestoreView
A.afterRestoreView
B.afterRestoreView
If any control events have been fired they are executed following the afterRestoreView events.

The following now occur every time following the PageLoad or restoreView events
X.beforeRenderResponse
A.beforeRenderResponse (only occured with PageLoad in 8.5.0)
B.beforeRenderResponse (only occured with PageLoad in 8.5.0)
X.afterRenderResponse
A.afterRenderResponse (only occured with PageLoad in 8.5.0)
B.afterRenderResponse (only occured with PageLoad in 8.5.0)

The key difference for 8.5.1 being that the beforeRenderResponse and afterRenderResponse are now executed for the XPage and ALL custom controls regardless of whether a partial refresh or full refresh occurs.
Note: This is only a partial listing as the Document events are not (yet) included.

The same observations are still relevant:-
  1. PageLoad events are a good place to place code you only wish to execute the very first time the page is created.
  2. afterRestoreView events seem to be the best place for code that you wish to execute each time a refresh occurs.
  3. Events on a page/control will execute after the afterRestoreView events have fired so they will have access to any variables/object you create in these events.
  4. To have code execute every time the page is processed you need to place it in a PageLoad and an afterRestoreView event
  5. Wen placing code in a control's afterPageLoad event don't assume the beforePageLoad events of the other controls have fired or that the page's afterPageLoad has fired.
You can test this out on-line using a demo XPage I have created as part of a new XPages Kindergarten section of the .Domino Framework: http://www.dominoframework.com/DominoFramework.nsf/XPK_Events.xsp

Wednesday
09Sep2009

Client-Side Events for Partial Updates: onStart, onComplete, onError

Hello All you XPages geeks out there.  Today I bring you a bit of good news from the land of 8.5.1!

There are three new CLIENT-SIDE events you can hook into when you do a partial update.

onStart - gets called just before the XSP handler submits the AJAX call to get and process the partial update

onComplete - gets called after the partial update is completed and has been processed, and the DOM updated

onError - gets called if an error happens during the xhrGet or xhrPost process (equiv to the error parameter of dojo's xhrGet/xhrPost) - IF YOU DEFINE onError YOU OVERRIDE THE DEFAULT ERROR MESSAGE. Which is a good thing because you can give your users better context to the problem, etc.

What can you do with these? Well, for example:

- if you have a Partial Update that is going to take a long time, with onStart, you can set the default 'timeout parameter' for a partial update (XSP.submitLatency = 10000 // 10 Seconds (default is 6)), and warn your user that its going to take a bit longer than expected, etc.

- For the long partial update, with onComplete you can notify your user the update is complete, or If you use dojo's drag and drop functionality, you could use the onComplete to re-setup your drag and drop sources or targets. Or you could have the element start "invisible" and use the onComplete to fade in the element using dojo.fadeIn() for some extra "flair"

Ok, 'nuff examples, where do you set these up? Well, in your event handler that triggers the partial update of course! For example, if you have a button, and that button triggers a partial update, expand the button in the outline, and you'll see a Node for Event handler. Click that node, and in the All Properties, under 'events' you'll find the three events!

Happy Coding!

 

Oh, and BTW: IBM Lotus Notes/Domino and Lotus Notes Traveler 8.5.1 is prerelease code and there are no guarantees from IBM that the functionality presented or discussed will be in the final shipping product.