{"id":694,"date":"2012-05-03T08:15:15","date_gmt":"2012-05-03T06:15:15","guid":{"rendered":"http:\/\/hasselba.ch\/blog\/?p=694"},"modified":"2012-05-03T08:18:28","modified_gmt":"2012-05-03T06:18:28","slug":"xsnippet-cancel-a-partial-refresh-via-ssjs","status":"publish","type":"post","link":"https:\/\/hasselba.ch\/blog\/?p=694","title":{"rendered":"XSnippets: Cancel a partial refresh via SSJS"},"content":{"rendered":"<p>With the <a href=\"https:\/\/hasselba.ch\/blog\/?p=683#comment-247\" target=\"_blank\">assistance of Philippe Riand<\/a> I was able to shorten the <a title=\"Cancel a partial refresh via SSJS\" href=\"https:\/\/hasselba.ch\/blog\/?p=683\" target=\"_blank\">original idea<\/a> of canceling a partial refresh to a single SSJS function.\u00a0 By setting the HTTP header &#8222;<em>X-XspRefreshId<\/em>&#8220; to &#8222;<em>@none<\/em>&#8220; it is possible to get the same result as in the posting before, but there is no &#8222;Dojo hack&#8220; required.<\/p>\n<pre>function cancelPartialRefresh(){\r\n   var response = facesContext.getExternalContext()\r\n      .getResponse();\r\n\u00a0\u00a0 response.setHeader(\"X-XspRefreshId\", \"@none\");\r\n\u00a0\u00a0 response.reset();\r\n\u00a0\u00a0 response.commitResponse();\r\n\u00a0\u00a0 facesContext.responseComplete();\r\n}<\/pre>\n<p>To use this function you just have to call it.\u00a0 Here is the same example like in the previous posting:<\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;xp:view xmlns:xp=\"http:\/\/www.ibm.com\/xsp\/core\"&gt;\r\n   &lt;xp:button value=\"Label\" id=\"button1\"&gt;\r\n      &lt;xp:eventHandler event=\"onclick\" submit=\"true\"\r\n         refreshMode=\"partial\" refreshId=\"label1\"&gt;\r\n      &lt;\/xp:eventHandler&gt;\r\n   &lt;\/xp:button&gt;\r\n   &lt;xp:br\/&gt;&lt;xp:br\/&gt;\r\n   &lt;xp:label id=\"label1\"&gt;\r\n      &lt;xp:this.value&gt;\r\n      &lt;![CDATA[#{javascript:\r\n      function cancelPartialRefresh(){\r\n         var response = facesContext.getExternalContext()\r\n            .getResponse();\r\n         response.setHeader(\"X-XspRefreshId\", \"@none\");\r\n         response.reset();\r\n         response.commitResponse();\r\n         facesContext.responseComplete();\r\n      }\r\n\r\n\u00a0     var ajax = new com.ibm.xsp.ajax.AjaxUtil();\r\n      if( ajax.isAjaxPartialRefresh(facesContext) == true){\r\n         cancelPartialRefresh();\r\n         return; \/\/ stop execution of SSJS code\r\n      }\r\n      java.lang.System.currentTimeMillis();}]]&gt;\r\n      &lt;\/xp:this.value&gt;\r\n   &lt;\/xp:label&gt;\r\n&lt;\/xp:view&gt;<\/pre>\n<p>I have added the code to the <a title=\"openntf.org: XSnippets Contests\" href=\"http:\/\/www.openntf.org\/blogs\/openntf.nsf\/d6plinks\/NHEF-8TF9YU\" target=\"_blank\">XSnippet Contest<\/a>. Here is the link to the XSnippet:<a title=\"openntf.org: XSnippet - Cancel Partial Refresh\" href=\"http:\/\/openntf.org\/XSnippets.nsf\/snippet.xsp?id=cancel-partial-refresh\" target=\"_blank\"> http:\/\/openntf.org\/XSnippets.nsf\/snippet.xsp?id=cancel-partial-refresh<\/a><\/p>\n<p>If you want to read more information about the HTTP header\u00a0 you can read an <a title=\"Der neue HTTP Header \u2018X-XspRefreshId\u2019\" href=\"https:\/\/hasselba.ch\/blog\/?p=400\" target=\"_blank\">earlier posting<\/a> (Sorry, on german only).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>With the assistance of Philippe Riand I was able to shorten the original idea of canceling a partial refresh to a single SSJS function.\u00a0 By setting the HTTP header &#8222;X-XspRefreshId&#8220; to &#8222;@none&#8220; it is possible to get the same result &hellip; <a href=\"https:\/\/hasselba.ch\/blog\/?p=694\">Weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,75,19,9,27,82,76,81,74,40,24],"tags":[33,8,7,77,11,4,25,87,16,5,32,12,3,92,85],"class_list":["post-694","post","type-post","status-publish","format-standard","hentry","category-allgemein","category-dojo","category-html","category-javascript","category-performance","category-server","category-ssjs","category-web","category-xpages","category-xsnippet","category-xsp","tag-8-5-3","tag-dojo","tag-domino","tag-html","tag-http","tag-js","tag-partial-refresh","tag-performance","tag-server","tag-ssjs","tag-tipp","tag-web","tag-xpages","tag-xsnippet","tag-xsp"],"_links":{"self":[{"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/posts\/694","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=694"}],"version-history":[{"count":5,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/posts\/694\/revisions"}],"predecessor-version":[{"id":699,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/posts\/694\/revisions\/699"}],"wp:attachment":[{"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=694"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=694"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=694"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}