2016-06-17 7 views
1

私はCSJSを使用してsessionScopeとをクリアし、いくつかのより多くの経験と優れたのXPagesプログラマから盗んだ素敵な機能を持っている:csjsを使用してsessionScope変数をクリアすることはできますか?

function clearMap(map:Map){ // Get iterator for the keys 
    var iterator = map.keySet().iterator(); // Remove all items 
    while(iterator.hasNext()){ 
     map.remove(iterator.next()); 
} 

これが正常CSJSから呼び出されるように変更することはできますか? sessionScope以来

答えて

6

あなたはSSJSコードでそれをクリアする必要があり、サーバ側オブジェクトです。 CSJSから直接クリアすることはできませんが、CSJSからSSJSコードを呼び出すことはできます。 CSJSからSSJSを呼び出すには、拡張ライブラリのJSON-RPCサービスを使用できます。ここで

は一例です。

<?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> 
+0

おかげで - 私は今週後半に試してみるだろう。 –

関連する問題