Herty
Herty

Reputation: 95

XSP.showDialog doesn't work in onStart event?

I have the following test XPage.

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
    xmlns:xe="http://www.ibm.com/xsp/coreex">
    <xp:panel id="pagePanel">
        <xp:text escape="true" id="didThePageCompile">
            <xp:this.value><![CDATA[#{javascript:var d = new Date();
return d.toLocaleString();}]]></xp:this.value>
        </xp:text>
        <xp:br></xp:br>
        <xp:button value="Label" id="button1">
            <xp:eventHandler event="onclick" submit="true"
                refreshMode="partial" refreshId="dialog1"
                onStart="XSP.openDialog('#{id:dialog1}')" 
                onComplete="XSP.closeDialog('#{id:dialog1}')">
            <xp:this.action><![CDATA[#{javascript:var agent = database.getAgent("runLongTime");
var response = agent.run();

// var d = getComponent("dialog1"); 
// d.show();
}]]></xp:this.action>
</xp:eventHandler>
</xp:button>
<xe:dialog id="dialog1" title="Test Dialog">This is a test dialog</xe:dialog></xp:panel>
</xp:view>

The agent "runLongTime" just sleeps for 10 seconds. This works fine. When I click the button however the dialog box does not show up. I checked the source and it generates the correct code, and that code works when I manually put it into the console.

I don't get any errors and the agent executes fine. I've also tried changing the refreshId to "pagePanel", but still the same.

Upvotes: 2

Views: 1970

Answers (2)

Pantelis Botsas
Pantelis Botsas

Reputation: 31

as far as I can see here, you are trying to open/close the same dialog. Some days ago I got the same issue and wondered why this was not working.

Finally I checked the events and ended with the spectacular result that onStart and onComplete fired up almost parallel.

Maybe you could try to insert a timeout (window.timeout) before calling the XSP.closeDialog event.

Upvotes: 0

Tim Tripcony
Tim Tripcony

Reputation: 8086

XSP.openDialog() and XSP.closeDialog() each trigger a partial refresh. The XPages client-side API includes logic for preventing multiple partial refresh operations from executing in parallel, which is likely preventing your dialog from displaying because by the time it attempts to run the refresh to show the dialog, it's already running your button event.

Add a JSON-RPC (called "Remote Services" in the control palette) to the page. Move your button's server event code to a method of the RPC. You can then change the button event to be purely client-side: call XSP.openDialog(), then call the RPC method and close the dialog in the onComplete of that method. This should prevent the race condition you're currently experiencing.

Upvotes: 7

Related Questions