Calling Server-side JS/Code during Mobile Page Transitions - 2: Using RPC Method Handlers (9.0.1)


<?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:this.beforePageLoad>
	    <![CDATA[#{javascript:
			viewScope.invokedBy = "<nobody>"
	    }]]>
	</xp:this.beforePageLoad>
	<xe:singlePageApp id="singlePageApp1"
		selectedPageName="pageOne">
		<xe:appPage id="appPage1" pageName="pageOne" resetContent="true">
			<xe:djxmHeading id="djxmHeading1" transition="slide"
				moveTo="pageTwo" label="Page One" back="Page Two">
			</xe:djxmHeading>
			<xp:text id="p1Text"
				value="#{javascript:println('p1Text'); return 'p1Text';}">
			</xp:text>
			<xp:br></xp:br>
			<xp:text id="computedField1" value="#{javascript:viewScope.invokedBy}">
			</xp:text>
		</xe:appPage>
		<xe:appPage id="appPage2" pageName="pageTwo" resetContent="true">
			<xe:djxmHeading id="djxmHeading2" transition="slide"
				moveTo="pageOne" label="Page Two" back="Page One">
			</xe:djxmHeading>
			<xp:text id="p2Text"
				value="#{javascript:println('p2Text'); return 'p2Text';}">
			</xp:text>
			<xp:br></xp:br>
			<xp:text id="computedField2" value="#{javascript:viewScope.invokedBy}">
			</xp:text>
		</xe:appPage>
	</xe:singlePageApp>
	<xp:scriptBlock id="scriptBlock1">
		<xp:this.value>
			<![CDATA[
				XSP.addOnLoad(function(){
					var appPage1 = dijit.byId("#{id:appPage1}");
					if(null != appPage1){
						dojo.connect(appPage1, "onBeforeTransitionIn", function(){
							var invoker = "onBeforeTransitionIn appPage1";
							console.log("pre-invocation: " + invoker);
							var deferred = myRPC.myMethod(invoker);
							deferred.addCallback(function(result) {
								console.log("post-invocation: " + result);
								XSP.partialRefreshGet(appPage1.domNode.firstElementChild.id);
							});
						});
				  	}
					var appPage2 = dijit.byId("#{id:appPage2}");
					if(null != appPage2){
						dojo.connect(appPage2, "onBeforeTransitionIn", function(){
							var invoker = "onBeforeTransitionIn appPage2";
							console.log("pre-invocation: " + invoker);
							var deferred = myRPC.myMethod(invoker);
							deferred.addCallback(function(result) {
								console.log("post-invocation: " + result);
								XSP.partialRefreshGet(appPage2.domNode.firstElementChild.id);
							});
						});
				  	}
				});
    		]]>
		</xp:this.value>
	</xp:scriptBlock>
	<xe:jsonRpcService id="jsonRpcService1" serviceName="myRPC"
		state="true">
		<xe:this.methods>
			<xe:remoteMethod name="myMethod">
				<xe:this.arguments>
					<xe:remoteMethodArg name="myArg" type="string"></xe:remoteMethodArg>
				</xe:this.arguments>
				<xe:this.script>
					<![CDATA[
						println("invocation: " + myArg);
						viewScope.invokedBy = myArg;
						return viewScope.invokedBy;
					]]>
				</xe:this.script>
			</xe:remoteMethod>
		</xe:this.methods>
	</xe:jsonRpcService>
</xp:view>
All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
No comments yetLogin first to comment...