Workaround for Perfomance Problems with Data containers


/*****
 *** 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
All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
1 comment(s)Login first to comment...
Sven Hasselbach
(at 15:15 on 07.03.2012)
@Tony McGuckin:
Maybe for repeat controls, but data context variables don't have these options (as far as I know)