データコンテナのパフォーマンスの問題に対する対処法

/*****
 *** Workaround for Perfomance Problems with Data containers
 ***
 *** Prevents multiple recalculation during JSF
 *** lifecycle & partial refresh if not required
 ***
 *** Works for all data containers like repeat controls,
 *** data tables etc.
 ***
 *** UPDATE, 06/03/2012, 13:11:
 *** Works currently only with serializable data.
 ***
 *****/
  
 
function calculate(){
  /*** add your own code here ***/
}
 
/*** change client id if required ***/
var clientId = getClientId( this.id );
var keyId = "fixData-" + clientId;
var data = null;
 
/*** If data were never calculated before, calculate them **/
if( viewScope.containsKey( keyId ) === false){
   data = calculate();
   viewScope.put( keyId, data );
   return data;
}
 
/*** Check for partial refreshs and refreshed id ***/
if( com.ibm.xsp.ajax.AjaxUtil.isAjaxPartialRefresh(facesContext) === true ){
   var rId = com.ibm.xsp.ajax.AjaxUtil.getAjaxComponentId( facesContext  );
   if( rId !== clientId )
  return viewScope.get( keyId );
}
 
 
/*** Prevent multiple calculation during JSF lifecycle ***/
if( requestScope.containsKey( keyId ) == true ){
  value = viewScope.get( keyId );
}else{
  value = calculate();
  viewScope.put( keyId , value );
  requestScope.put( keyId , true );
}
 
value





このコードはデータコンテナ(繰り返しコントロール、データ表など)が必要のないときに再計算されることを防ぐもの、コードはこのデータコンテナの <xp:this.value></xp:this.value> セクションに追加します。

こちらが使い方のサンプルです:

*** 使用前 ***

<xp:repeat id="repeat1" rows="30">
 <xp:this.value><![CDATA[#{javascript:
    var test = new java.util.Vector();
    test.add( java.lang.System.currentTimeMillis() )
    return test;
 }]]></xp:this.value>
</xp:repeat>

*** 使用後 ***

<xp:repeat id="repeat1" rows="30">
 <xp:this.value><![CDATA[#{javascript:
    function calculate(){
       var test = new java.util.Vector();
       test.add( java.lang.System.currentTimeMillis() )
       return test;
    }

    /*** change client id if required ***/
    var clientId = getClientId( this.id );
    var keyId = "fixData-" + clientId;
    var data = null;

    /*** If data were never calculated before, calculate them **/
    if( viewScope.containsKey( keyId ) === false){
      data = calculate();
       viewScope.put( keyId, data );
       return data;
    }

    /*** Check for partial refreshs and refreshed id ***/
    if( com.ibm.xsp.ajax.AjaxUtil.isAjaxPartialRefresh(facesContext) === true ){
       var rId = com.ibm.xsp.ajax.AjaxUtil.getAjaxComponentId( facesContext  );
       if( rId !== clientId )
    return viewScope.get( keyId );
    }


    /*** Prevent multiple calculation during JSF lifecycle ***/
    if( requestScope.containsKey( keyId ) == true ){
       value = viewScope.get( keyId );
    }else{
       value = calculate();
       viewScope.put( keyId , value );
       requestScope.put( keyId , true );
    }

    value
 }]]></xp:this.value>
</xp:repeat>

*** さらに詳細を知りたい場合はこちらを参照 ***
http://www-10.lotus.com/ldd/xpagesforum.nsf/topicThread.xsp?action=openDocument&documentId=56E9B8537DA50A90852579A6002EAC64
http://atnotes.de/index.php?topic=53754.0
http://hasselba.ch/blog/?p=572

JavaScript (Server)
katoman
July 13, 2015 at 11:26 AM
Rating
0





No comments yetLogin first to comment...