XSP.addOnLoad call leads to an error "XSP is not a valid object"

Hi,

this is quite a strange one: just tried to implement a script block in an XPage to then be able to use XSP.addOnLoad to execute some function onLoad. But it doesn’t work, all I get is an “Unexpected runtime error” telling me that XSP was not a vlid object.

So I built a fresh XPage ina different database and included nothing but that script block, to be sure that I hadn’t run into some different problem. But no: same thing here.

Here’s the raw XML for my test page:

<?xml version="1.0" encoding="UTF-8"?>

<xp:view xmlns:xp=“http://www.ibm.com/xsp/core”>

<xp:scriptBlock id="scriptBlock1">

	<xp:this.value><![CDATA[#{javascript:XSP.addOnLoad(

function() {

	alert("it's me!");

}

)}]]></xp:this.value>

</xp:scriptBlock>

</xp:view>

And here’s the debugging message:

Unexpected runtime error

The runtime has encountered an unexpected error.

Error source

Page Name:/testAddOnLoad.xsp
Control Id: scriptBlock1
Property: value

Exception

Error while executing JavaScript computed expression
Script interpreter error, line=1, col=5: Error calling method ‘addOnLoad(function)’: ‘XSP’ is not a valid object

Javascript code

1: XSP.addOnLoad(
2: function() {
3: alert(“it’s me!”);
4: }
5: )

► ▼ Stack Trace

Don’t have a clue what’s wrong here, as I remember having used XSP.addOnLoad successfully in the past…

Subject: Re: XSP.addOnLoad

You’re problem is the “#{javascript:” - the script block is only expecting javascript.

If you remove this and the “}” at the end, it works. You should have:

<?xml version="1.0" encoding="UTF-8"?>

<xp:view xmlns:xp=“http://www.ibm.com/xsp/core”>

<xp:scriptBlock id="scriptBlock1">

	<xp:this.value><![CDATA[XSP.addOnLoad(

function() {

alert(“it’s me!”);

}

)]]></xp:this.value>

</xp:scriptBlock>

</xp:view>

Subject: Works alright, but…

Paul,

thanks a lot for the hint, of course it’s also working here now.

Problem is that if I include an output script control on my page then open its All Properties - data - value section end enter my code using the script editor then the #{javascript:…} block is created for me, meaning I didn’t code it manually. This still is true for 8.5.1 (just tested it).