XPages – For … Loop issue

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Ā  &lt; or &#60; .

5 thoughts on “XPages – For … Loop issue

  1. 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.

  2. 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);

Comments are closed.