It's very common to see new articles and tips about xpages in planet Lotus every day. Today I thought to make myself familiar with xpages. To do so I thought to try with very popular and simple program alerting "Hello World" when xpage loads .

Here is what I've tried,


When I view my xpage on web got something like ,


I'm using 8.5.1 designer with 8.5 server . Any clue ?

Is it the right way to execute client side JavaScript on xpages ?

6 Responses to "XPages : How do you do ? ( Part 1)"

  1. gravatar Nate Says:

    Unfortunately, there is an incompatibility between the 8.5.1 client and the 8.5.0 server when it comes to client-side Javascript. You need to either use to the 8.5.0 Designer, or learn the SOURCE syntax for 8.5.0 in 8.5.1. I'll ask Tim to post a reply with details.

  2. gravatar Rishi Says:

    Thanks Nate!

    So the way I've tried to run client side JavaScript is the correct way ?

  3. gravatar Tim Tripcony Says:

    Rishi, here's the approach we use:

    1. Select "Script Editor" instead of "Simple Actions" and just type in the client-side script.
    2. Switch to the Source tab, and you'll see something like this:

    <xp:eventHandler event="onclick" submit="false">

    <xp:this.script><![CDATA[alert("Hello World!");]]></xp:this.script>

    </xp:eventHandler>


    3. If you then tried to load the page, you'd see the same error. So first we have to "wrap" the script tag inside two additional tags, which looks like this:

    <xp:eventHandler event="onclick" submit="false">

    <xp:this.handlers>

    <xp:handler type="text/javascript">

    <xp:this.script><![CDATA[alert("Hello World!");]]></xp:this.script>

    </xp:handler>

    </xp:this.handlers>

    </xp:eventHandler>


    The good news is that the page will now load correctly whether the server is running 8.5.0 or 8.5.1. The bad news is that if you edit the script event from the Events pane again, it removes those additional tags, so you have to go back into the Source and add them back in again. Thankfully, you can edit any other properties of the control (including server-side events, if the control has a "dual event" - runs both client-side and server-side code - or has handlers for multiple events) and the tags will be left intact... you don't have to add those tags back in every time you modify the page. Just remember that if you want to make changes to the client-side event, it's best to just switch to Source and type the changes in there. To be honest, I do almost all of my XPage coding directly in the Source because this isn't the only behavior where I would lose more time because of Designer quirks than I'd gain by setting the same properties using the visual editor.

  4. gravatar Rishi Says:

    Thanks Tim It's perfect!

  5. gravatar Paul Says:

    http://xpagesblog.com/xpages-blog/2009/10/16/xpages-things-to-be-aware-of-when-using-an-851-designer-with.html

    http://xpagesblog.com/xpages-blog/2009/12/4/things-to-be-aware-of-when-upgrading-your-85-xpages-applicat.html

  6. gravatar Rishi Says:

    Thanks Paul ! Initially I was searching in xpage blog but unfortunately missed somehow.

Leave a Reply

preload preload preload