VladP
VladP

Reputation: 901

SSJS is not executed on xPage

I met some strange problem. A page button does not execute SSJS when it's clicked first time after page load. But does work when you click it again. I found it especially when you clear browser cache.

  1. Try to clear Chrome cache (Ctrl+Shift+Del. Clear everything).
  2. Restart Chrome.
  3. Try to load this page TEST.xsp. First pass server login page.
  4. Click 'My Button'. It doesn't do anything. It's supposed to e.g. redirect to same page with a new parameter e.g. param1=true (sure it should do nothing, but just add param1=true to the URL)
  5. Click it again. It does work

What could cause this behavior? It can be any SSJS not exactly context.redirectToPage. But it works only when you click button second time. Same problem found on FF but it does work in IE.

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
    <xp:button id="button1" styleClass="btn btn-primary btn-sm"
        value="My Button" title="My Button">
            <span class="glyphicon glyphicon-edit"></span>
        <xp:eventHandler event="onclick" submit="true"
            refreshMode="complete" id="eventHandler10">
            <xp:this.action><![CDATA[#{javascript:context.redirectToPage("TEST.xsp?param1=true");}]]></xp:this.action>
        </xp:eventHandler>
    </xp:button>
</xp:view>

Here is my app configuration options: enter image description here enter image description here

Upvotes: 3

Views: 359

Answers (3)

VladP
VladP

Reputation: 901

This does help when you put it into afterPageLoad event.

if(!sessionScope.APP_LOADED){
    sessionScope.put("APP_LOADED", true);
    context.reloadPage();
}else if(sessionScope.APP_LOADED==false){
    sessionScope.put("APP_LOADED", true);
    context.reloadPage();   
}

Upvotes: 1

D.Bugger
D.Bugger

Reputation: 2359

I think I had a similar problem. I had to add an OnClientLoad action, with nothing in it. Why exactly I don't know.

Upvotes: 0

Georg Kastenhofer
Georg Kastenhofer

Reputation: 1417

You have to set the following parameter, then it should work as expected:

enter image description here

Upvotes: 0

Related Questions