With the assistance of Philippe Riand I was able to shorten the original idea of canceling a partial refresh to a single SSJS function. By setting the HTTP header „X-XspRefreshId“ to „@none“ it is possible to get the same result as in the posting before, but there is no „Dojo hack“ required.
function cancelPartialRefresh(){ var response = facesContext.getExternalContext() .getResponse(); response.setHeader("X-XspRefreshId", "@none"); response.reset(); response.commitResponse(); facesContext.responseComplete(); }
To use this function you just have to call it. Here is the same example like in the previous posting:
<?xml version="1.0" encoding="UTF-8"?> <xp:view xmlns:xp="http://www.ibm.com/xsp/core"> <xp:button value="Label" id="button1"> <xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="label1"> </xp:eventHandler> </xp:button> <xp:br/><xp:br/> <xp:label id="label1"> <xp:this.value> <![CDATA[#{javascript: function cancelPartialRefresh(){ var response = facesContext.getExternalContext() .getResponse(); response.setHeader("X-XspRefreshId", "@none"); response.reset(); response.commitResponse(); facesContext.responseComplete(); } var ajax = new com.ibm.xsp.ajax.AjaxUtil(); if( ajax.isAjaxPartialRefresh(facesContext) == true){ cancelPartialRefresh(); return; // stop execution of SSJS code } java.lang.System.currentTimeMillis();}]]> </xp:this.value> </xp:label> </xp:view>
I have added the code to the XSnippet Contest. Here is the link to the XSnippet: http://openntf.org/XSnippets.nsf/snippet.xsp?id=cancel-partial-refresh
If you want to read more information about the HTTP header you can read an earlier posting (Sorry, on german only).
Pingback: SSJS - @CancelPartialRefresh - By Ulrich Krause - eknori.de