Wednesday, March 3, 2010

"onload" Event in XPages

Developers who are experienced in traditional web applications in Lotus Notes it becomes a nightmare when they start to work with XPages.

One of the initial issues that I faced is - the struggle to gain control of the onload event in the XPages as the available events in the XPages like the afterPageLoad etc... only allows Serverside script and it becomes expensive to hit the server every time in terms of application's performance.

The following code fragment shall help people who face this issue, and will help them gain access to the XPage's onload event.

<script language="Javascript">
XSP.addOnLoad(alert('I am in XPage onload'));
</script></b>

Add this snippet of code in the Source panel and ensure that it is not nested inside any other existing tags.An ideal place would beneath the lines which say (sort of),

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
 

Now after performing the above step, preview your XPage and voila, you will get the alert saying "I am in XPage onload"

No comments:

Post a Comment