Search code examples
xpageslotus-noteshcl

Xpages onClick execution sequence


I want to create a button that executes different actions/scripts in a particular sequence. First, I want to save the current document (server side action). After saving the document, a partial refresh is performed. Then a client side script should be carried out. When finishing this script, a new page is opened.

My current button:

<xp:button id="saveButton" value="Save">
    <xp:this.rendered><![CDATA[#{javascript:if(document1.isEditable()){
           return true;
          }
          else{ 
           return false
          }
    }]]></xp:this.rendered>
                    <xp:eventHandler event="onclick" submit="true"
                        refreshMode="partial" immediate="false" save="true" refreshId="saveButton">

                        <xp:this.action>

                            <xp:actionGroup>
                                <xp:saveDocument var="document1"></xp:saveDocument>

                                <xp:openPage name="/viewer.xsp"
                                    target="openDocument">
                                </xp:openPage>
                            </xp:actionGroup>
                        </xp:this.action>



                        <xp:this.script>
                            <xp:executeClientScript>
                                <xp:this.script><![CDATA[
                                    someScript();
                                ]]></xp:this.script>
                            </xp:executeClientScript>
                        </xp:this.script>
                    </xp:eventHandler>
                </xp:button> 

Currently, this button first executes all server side events and then the client script. Is there a solution to arrange the order of execution, so that I can execute server->client->server?

EDITED:

The functionality I want, splitted in three buttons:

<xp:button value="Label" id="execute1">
    <xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="execute2">
        <xp:this.action>
            <xp:saveDocument var="document1"></xp:saveDocument>
</xp:this.action></xp:eventHandler></xp:button>


<xp:button value="Label" id="execute2"><xp:eventHandler event="onclick" submit="false">
    <xp:this.script>
        <xp:executeClientScript>
            <xp:this.script><![CDATA[
            someScript();
        }});]]></xp:this.script>
        </xp:executeClientScript>
</xp:this.script></xp:eventHandler></xp:button>


<xp:button value="Label" id="execute3"><xp:eventHandler event="onclick" submit="true" refreshMode="complete">
    <xp:this.action>
        <xp:openPage name="/viewer.xsp" target="openDocument"></xp:openPage>
</xp:this.action></xp:eventHandler></xp:button>

So I would click execute1 => execute 2 => execute 3


Solution

  • Apart from view.postScript, as Paul suggests, you can add client-side JavaScript to onComplete for the event. This will run after the event is finished. I'm not certain if there is a big difference behind the scenes in regards to view.postScript vs onComplete.

    You could create a hidden button (style="display: none;") that runs the second server side code. and trigger the click event for that after the first server event is complete.