Subscribe to Partial Refresh I/O Channel Events


<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.ibm.com/xsp/core xsdxp://localhost/xsp~core.xsd">
	<xp:this.properties>
		<xp:parameter name="xsp.client.script.dojo.djConfig"
			value="ioPublish:true">
		</xp:parameter>
	</xp:this.properties>
	<xp:button value="SSJS: Sniff this Ajax Request" id="button1">
		<xp:eventHandler event="onclick" submit="true"
			refreshMode="partial" refreshId="computedField1">
			<xp:this.action>
				<![CDATA[#{javascript:
					viewScope.foo = @Unique()
				}]]>
			</xp:this.action>
		</xp:eventHandler>
	</xp:button>
	<xp:button value="CSJS: Sniff this Ajax Request" id="button2">
		<xp:eventHandler event="onclick" submit="false">
			<xp:this.script>
				<![CDATA[
					XSP.partialRefreshGet("#{id:computedField1}");
				]]>
			</xp:this.script>
		</xp:eventHandler>
	</xp:button>
	<xp:br></xp:br>
	<xp:br></xp:br>
	<xp:text escape="true" id="computedField1"
		value="#{javascript:viewScope.foo}">
	</xp:text>
	<xp:br></xp:br>
	<xp:br></xp:br>
	<xp:scriptBlock id="scriptBlock1">
		<xp:this.value>
			<![CDATA[
				dojo.subscribe("/dojo/io/start", function(data){
					// Triggered when there are no outstanding IO requests,
					// and a new IO request is started. No arguments are passed with this topic.
				    console.log("triggered on /dojo/io/start channel");
				    
				    var div = XSP.getElementById("#{id:hiddenDiv}");
				    if(null != div){
				    	div.style.display = "inline";
				    }
				});
				
				dojo.subscribe("/dojo/io/send", function(data){
					// Triggered whenever a new IO request is started.
					// It passes the dojo.Deferred for the request.
				    console.log("triggered on /dojo/io/send channel");
				});
				
				dojo.subscribe("/dojo/io/load", function(data){
					// Triggered whenever an IO request has loaded
					// successfully. It passes the response and the
					// dojo.Deferred for the request.
				    console.log("triggered on /dojo/io/load channel");
				});
				
				dojo.subscribe("/dojo/io/error", function(data){
					// Triggered whenever an IO request has errored.
					// It passes the error and the dojo.Deferred
					// for the request with the topic.
				    console.log("triggered on /dojo/io/error channel");
				});
				
				dojo.subscribe("/dojo/io/done", function(data){
					// Triggered whenever an IO request has completed,
					// either by loading or by erroring. It passes the error and
					// the dojo.Deferred for the request with the topic.
				    console.log("triggered on /dojo/io/done channel");
				    
				    var div = XSP.getElementById("#{id:hiddenDiv}");
				    if(null != div){
				    	div.style.display = "none";
				    }
				});
				
				dojo.subscribe("/dojo/io/stop", function(data){
					// Triggered when all outstanding IO requests have
					// finished. No arguments are passed with this topic.
				    console.log("triggered on /dojo/io/stop channel");
				});
			]]>
		</xp:this.value>
	</xp:scriptBlock>
	<xp:div id="hiddenDiv" style="display:none">Hello World</xp:div>
</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...