XSP.showDialog doesn't work in onStart event?

安稳与你 提交于 2019-12-24 01:48:34

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/14812584/xsp-showdialog-doesnt-work-in-onstart-event

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!