While working on some XPages app dev, I encountered a problem with for … loops in an output script block when the loop is used together with other XPages elements in the block.
There are two ways of filling the content of the script block. The picture below shows both ways and in both cases I get an error message and the code does not compile.
The only way to get rid of the error in the second sample was to replace the “<” with a special character substitution codeĀ < or < .
You should be able to simplify your code. You can write inline #{javascript:} snippets inside the CDATA block.
E.g.
[xp:scriptBlock]
[xp:this.value][![CDATA[var test = ‘#{javascript:return Date()}’;
alert( test );]]][/xp:this.value]
[/xp:scriptBlock]
Results in an alert-box with the date an time from the server.
I don’t think it is possible to generate server-side objects (xp:text) within a client-side script.
I think a better approach is to move the text object outside the scriptblock, put the scriptblock inside a panel and add a ‘onChange’ event to the textbox. Partial refresh the created panel so the client-side script is recalculated. From within your scriptBlock add this :
var os = ‘#{javascript:return getComponent(“org”).getValue();}’ ;
alert(os);
the correct way to do this is:
<![CDATA[
var os = '#{javascript:getComponent("org").getValue()}';
for (i=0;i
hmmm .. most of my comment got eaten, but i think its mostly there
Thanks all for commenting on this topic.
@Jeremy: most of the content got lost, but I got the idea. Thx