I have a nice function that I stole from some more experienced and better xpages programmer that clears sessionScope using CSJS:
function clearMap( map:Map ){ // Get iterator for the keys
var iterator = map.keySet().iterator(); // Remove all items
while( iterator.hasNext() ){
map.remove( iterator.next() );
}
Can this be modified to be successfully called from CSJS?
Since sessionScope
is a server side object you have to clear it with SSJS code. You can't clear it directly from CSJS but you can call SSJS code from CSJS. To call SSJS from CSJS you can use the JSON-RPC Service from the extension library.
Here is an example:
<?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">
<xe:jsonRpcService id="jsonRpcService1" serviceName="myRpcService">
<xe:this.methods>
<xe:remoteMethod name="clearSessionScope">
<xe:this.script>
<![CDATA[
var iterator = sessionScope.keySet().iterator();
while( iterator.hasNext() ){
sessionScope.remove( iterator.next() );
}
return "sessionScope cleared";
]]>
</xe:this.script>
</xe:remoteMethod>
</xe:this.methods>
</xe:jsonRpcService>
<xp:button value="Clear sessionScope" id="button1">
<xp:eventHandler event="onclick" submit="false">
<xp:this.script>
<![CDATA[
var deferred = myRpcService.clearSessionScope();
deferred.addCallback(function(result) {
alert(result);
});
]]>
</xp:this.script>
</xp:eventHandler>
</xp:button>
</xp:view>