Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Patch for Offline problem in SmartClient 8.0

    The Offline support new to SmartClient release 8.0 contains a bug that causes repeated put()s interleaved with browser resets to randomly overwrite stored values. This problem only arises when using the UserData persistence strategy, which is the only strategy supported for IE6 and IE7. Note that we also use this strategy by default with IE8, but IE8 can actually support HTML5-style offline storage - you can switch this on by setting isc.Offline.userDataPersistenceInIE8 to false.

    The following patch code added to the HTML bootstrap file in your application after loading the SmartClient libraries fixes this issue (you can paste the code directly into a script block or save it as a .js file and include it). Note that this patch is large because it contains the entire Offline module. This is because it is factored in a way that makes it possible to run standalone, which makes it difficult to patch individual methods. The actual patch only affects the buildNextAttributeInfo() method.

    Code:
    //----------------------------------------------------------------------------
    // Isomorphic SmartClient 8.0 patch
    // Purpose: Fixes error in Offline persistence (Internet Explorer "UserData" 
    // storage strategy only) where repeated put()s interleaved with browser resets
    // were causing random overwrites of stored values
    //
    // NOTE: This patch only actually affects the "buildNextAttributeInfo" method, but the 
    // UserDataPersistence class is factored in such a way that makes patching individual 
    // methods difficult
    // 
    // Applies to SmartClient 8.0 builds only - version "SC_SNAPSHOT-2011-01-05" (LGPL)
    // or "SC_SNAPSHOT-2011-01-06" (commercial builds)
    //----------------------------------------------------------------------------
    if (window.isc != null) {
        if (isc.version.startsWith("SC_SNAPSHOT-2011-01-05") ||
            isc.version.startsWith("SC_SNAPSHOT-2011-01-06")) {
    (function(){var Offline={explicitOffline:null,isOffline:function(){if(this.explicitOffline!==null)return this.explicitOffline;var offline=window.navigator.onLine?false:true;return offline},goOffline:function(){this.explicitOffline=true},goOnline:function(){this.explicitOffline=false},useNativeOfflineDetection:function(){this.explicitOffline=null},KEY_PREFIX:"isc-",LOCAL_STORAGE:"localStorage",GLOBAL_STORAGE:"globalStorage",DATABASE_STORAGE:"databaseStorage",GEARS_DATABASE_API:"gears database api",USERDATA_PERSISTENCE:"userData persistence",GOOGLE_GEARS:"google gears",NO_MECHANISM:"no discovered mechanism",maxResponsesToPersist:100,userDataPersistenceInIE8:true,localStorageType:function(){if(window.localStorage){if(!this.userDataPersistenceInIE8||!isc.Browser.isIE){return this.LOCAL_STORAGE}}
    if(window.globalStorage)return this.GLOBAL_STORAGE;if(window.openDatabase)return this.DATABASE_STORAGE;if(isc.Browser.isIE&&isc.Browser.version>=5){if(!UserDataPersistence.isInitialized)UserDataPersistence.init();return this.USERDATA_PERSISTENCE}
    return this.NO_MECHANISM},getNativeStoredValuesCount:function(){switch(this.localStorageType()){case this.LOCAL_STORAGE:return localStorage.length;break;case this.USERDATA_PERSISTENCE:return UserDataPersistence.getNativeStoredValuesCount();break;case this.GLOBAL_STORAGE:case this.DATABASE_STORAGE:case this.GEARS_DATABASE_API:case this.GOOGLE_GEARS:break}},getSCStoredValuesCount:function(){var entries=this.get(this.countKey);entries=entries?entries*1:0;return entries},getKeyForNativeIndex:function(index){switch(this.localStorageType()){case this.LOCAL_STORAGE:return localStorage.key(index);case this.USERDATA_PERSISTENCE:return UserDataPersistence.getKeyForNativeIndex(index);break;case this.GLOBAL_STORAGE:case this.DATABASE_STORAGE:case this.GEARS_DATABASE_API:case this.GOOGLE_GEARS:break}},clearCache:function(){var count=this.getSCStoredValuesCount();while(this.getSCStoredValuesCount()>0){this.removeOldestEntry();if(this.getSCStoredValuesCount()==count)break;count=this.getSCStoredValuesCount()}},clearCacheNatively:function(){if(this.localStorageType()==this.USERDATA_PERSISTENCE){UserDataPersistence.clearCacheNatively();return}
    var count=this.getNativeStoredValuesCount();isc.logWarn("Removing all "+count+" entries from local storage");for(var i=0;i<count;i++){this.$786(this.getKeyForNativeIndex(0),false)}},logCacheContents:function(maxEntryLength){var contents=this.getCacheContents();this.logWarn("Dumping the contents of the browser's local storage:");for(var key in contents){var value=contents[key];if(value&&value.length>maxEntryLength){value=value.substring(0,maxEntryLength)}
    this.logWarn(key+" ===> "+value)}},getCacheContents:function(){var index=0,contents={},count=this.getSCStoredValuesCount();while(index<count){var key=this.getPriorityQueueKey(index);if(key.indexOf(this.KEY_PREFIX)==0)key=key.substring(this.KEY_PREFIX.length);contents[key]=this.get(key);index++}
    return contents},getCacheKeys:function(){var index=0,keys=[],count=this.getSCStoredValuesCount();while(index<count){var obj=this.getPriorityQueueKey(index);keys[keys.length]=key;index++}
    return keys},removeOldestEntry:function(){var key=this.getAndRemoveOldestFromPriorityQueue();if(key==null)return;this.remove(key,true)},$787:function(maxEntryLength){var doc=this.userDataSpan.xmlDocument;var maxEntryLength=100;this.logWarn("Dumping the contents of raw userData storage:");for(var i=0;i<this.userDataSpan.xmlDocument.firstChild.attributes.length;i++){var key=this.userDataSpan.xmlDocument.firstChild.attributes[i].name;var value=this.userDataSpan.getAttribute(key);if(value&&value.length>maxEntryLength){value=value.substring(0,maxEntryLength)+"..."}
    this.logWarn(key+" ===> "+value)}},put:function(key,value,recycleEntries){var ts=new Date().getTime();var oldValue=this.get(key);while(true){try{this.$788(key,value);break}catch(e){if(recycleEntries!==false&&this.isStorageException(e)){var entries=this.getStorageMetrics().storedEntries;if(entries>0){this.logWarn("Cache full; removing oldest entry and trying again");this.removeOldestEntry()}else{this.logWarn("Can't add this entry to browser-local storage, even "+"though the cache is empty - the item must be larger "+"than the browser's permitted cache space.");break}}else{throw e}}}
    var end=new Date().getTime();var pqOK=false,metricsOK=false;while(!pqOK||!metricsOK){try{if(!pqOK)this.addToPriorityQueue(key);pqOK=true;if(!metricsOK)this.updateMetrics("put",key,value,oldValue);metricsOK=true}catch(e){if(this.isStorageException(e)){if(recycleEntries!==false){var entries=this.getStorageMetrics().storedEntries;if(entries>0){this.logWarn("Cache full when updating priority queue or metrics; "+"removing oldest entry and trying again");this.removeOldestEntry();continue}}
    this.logWarn("Cache full when updating priority queue or metrics; rolling "+"back the entire update");this.$786(key);if(pqOK)this.removeFromPriorityQueue(key);this.rebuildMetrics();throw e}else{throw e}}}
    this.logWarn("put() with key: "+key+"\nitem: "+this.echoLeaf(value)+": "+(end-ts)+"ms. Maintaining the priority queue and metrics took "+"a further "+new Date().getTime()-end+"ms")},$788:function(key,value,applyPrefix){key=(applyPrefix===false?"":this.KEY_PREFIX)+key;switch(this.localStorageType()){case this.LOCAL_STORAGE:localStorage.setItem(key,value);break;case this.USERDATA_PERSISTENCE:UserDataPersistence.putValue(key,value);break;case this.GLOBAL_STORAGE:case this.DATABASE_STORAGE:case this.GEARS_DATABASE_API:case this.GOOGLE_GEARS:this.logError("Persistence method '"+this.localStorageType()+"' not yet supported");break}},isStorageException:function(e){switch(this.localStorageType()){case this.LOCAL_STORAGE:if(isc.Browser.isIE){return(e.number==-2147024882)}else if(isc.Browser.isMoz){return(e.name=="NS_ERROR_DOM_QUOTA_REACHED")}else{return(e.name=="QUOTA_EXCEEDED_ERR")}
    break;case this.USERDATA_PERSISTENCE:return(e.number==-2147024857)}},get:function(key){var ts=new Date().getTime(),item;switch(this.localStorageType()){case this.LOCAL_STORAGE:item=localStorage.getItem(this.KEY_PREFIX+key);break;case this.USERDATA_PERSISTENCE:item=UserDataPersistence.getValue(this.KEY_PREFIX+key);break;case this.GLOBAL_STORAGE:case this.DATABASE_STORAGE:case this.GEARS_DATABASE_API:case this.GOOGLE_GEARS:break}
    if(item)item=isc.clone(item);var end=new Date().getTime();this.logWarn("get() with key: "+key+"\nitem is: "+this.echoLeaf(item)+": "+(end-ts)+"ms");return item},remove:function(key,skipPriorityQueueUpdate){this.logWarn("Removing item for key: "+key);this.updateMetrics("remove",key);if(!skipPriorityQueueUpdate)this.removeFromPriorityQueue(key);this.$786(key)},$786:function(key,applyPrefix){key=(applyPrefix===false?"":this.KEY_PREFIX)+key;switch(this.localStorageType()){case this.LOCAL_STORAGE:localStorage.removeItem(key);break;case this.USERDATA_PERSISTENCE:UserDataPersistence.removeValue(key);break;case this.GLOBAL_STORAGE:case this.DATABASE_STORAGE:case this.GEARS_DATABASE_API:case this.GOOGLE_GEARS:break}},getUndecoratedKey:function(key){if(key&&key.startsWith(this.KEY_PREFIX)){key=key.substring(this.KEY_PREFIX.length)}
    return key},priorityQueueKey:"pq",addToPriorityQueue:function(userKey){this.removeFromPriorityQueue(userKey);var key=this.toInternalKey(userKey);var pqText=this.get(this.priorityQueueKey);if(pqText){eval("var pq = "+pqText)}else{var pq=[]}
    pq.push(key);this.$788(this.priorityQueueKey,this.serialize(pq))},removeFromPriorityQueue:function(userKey){var key=this.toInternalKey(userKey);var pqText=this.get(this.priorityQueueKey);if(pqText){eval("var pq = "+pqText)}else{var pq=[]}
    for(var i=0;i<pq.length;i++){if(pq[i]==key){var leading=pq.slice(0,i);var trailing=pq.slice(i+1);pq=leading.concat(trailing);break}}
    this.$788(this.priorityQueueKey,this.serialize(pq))},getAndRemoveOldestFromPriorityQueue:function(){var pqText=this.get(this.priorityQueueKey);if(pqText){eval("var pq = "+pqText)}else{var pq=[]}
    var oldest=pq.shift();this.$788(this.priorityQueueKey,this.serialize(pq));return this.toUserKey(oldest)},getPriorityQueueEntry:function(index){var key=this.getPriorityQueueKey(index);var value=this.get(key);var entry={};entry[key]=value;return entry},getPriorityQueueValue:function(index){var key=this.getPriorityQueueKey(index);return this.get(key)},getPriorityQueueKey:function(index){var pqText=this.get(this.priorityQueueKey);if(pqText){eval("var pq = "+pqText)}else{var pq=[]}
    return this.toUserKey(pq[index])},getPriorityQueue:function(){var pqText=this.get(this.priorityQueueKey);if(pqText){eval("var pq = "+pqText)}else{var pq=[]}
    return pq},toInternalKey:function(userKey){if(this.localStorageType()==this.USERDATA_PERSISTENCE){return UserDataPersistence.getDataStoreKey(this.KEY_PREFIX+userKey)}
    return userKey},toUserKey:function(internalKey){if(this.localStorageType()==this.USERDATA_PERSISTENCE){return this.getUndecoratedKey(UserDataPersistence.getUserKey(internalKey))}
    return internalKey},countKey:"storedEntryCount__",keyKey:"storedKeyBytes__",valueKey:"storedValueBytes__",updateMetrics:function(mode,key,value,oldValue){var realKey=this.KEY_PREFIX+key,storedEntries=this.get(this.countKey)||0,storedKeyBytes=this.get(this.keyKey)||0,storedValueBytes=this.get(this.valueKey)||0;storedKeyBytes=1*storedKeyBytes;storedValueBytes=1*storedValueBytes;if(mode=="remove"){var item=this.get(key);storedEntries--;storedKeyBytes-=realKey.length;storedValueBytes-=item.length}else{if(oldValue==null){storedEntries++;storedKeyBytes+=realKey.length;storedValueBytes+=value.length}else{storedValueBytes+=value.length-oldValue.length}}
    this.$788(this.countKey,storedEntries);this.$788(this.keyKey,storedKeyBytes);this.$788(this.valueKey,storedValueBytes)},rebuildMetrics:function(){var pq=this.getPriorityQueue(),entries=0,keyBytes=0,valueBytes=0;for(var i=0;i<pq.length;i++){var value=this.get(pq[i]);entries++;keyBytes+=pq[i].length;valueBytes+=value.length}
    this.$788(this.countKey,entries);this.$788(this.keyKey,keyBytes);this.$788(this.valueKey,valueBytes)},getStorageMetrics:function(){var storedEntries=this.get(this.countKey)||0,storedKeyBytes=this.get(this.keyKey)||0,storedValueBytes=this.get(this.valueKey)||0,countLen=0,keyLen=0,valueLen=0;if(storedEntries)countLen=storedEntries.length;if(storedKeyBytes)keyLen=storedKeyBytes.length;if(storedValueBytes)valueLen=storedValueBytes.length;storedEntries=1*storedEntries;storedKeyBytes=1*storedKeyBytes;storedValueBytes=1*storedValueBytes;var pqText=this.get(this.priorityQueueKey);var overhead=this.countKey.length+this.keyKey.length+this.valueKey.length+countLen+keyLen+valueLen;var pqLength=pqText==null?0:pqText.length+(this.KEY_PREFIX+this.priorityQueueKey).length;return{storedEntries:storedEntries,storedKeyBytes:storedKeyBytes,storedValueBytes:storedValueBytes,metricsOverhead:overhead,priorityQueue:pqLength,total:storedKeyBytes+storedValueBytes+overhead+pqLength}},getTotalStorageUsed:function(){var metrics=this.getStorageMetrics();return metrics.storedKeyBytes+metrics.storedValueBytes+metrics.metricsOverhead+metrics.priorityQueue},storeResponse:function(dsRequest,dsResponse){var ts=new Date().getTime();dsResponse.offlineTimestamp=ts;var trimmedRequest=this.trimRequest(dsRequest),key=this.serialize(trimmedRequest),value=this.serialize(this.trimResponse(dsResponse));this.logWarn("storeResponse serializing: "+(new Date().getTime()-ts)+"ms");if(this.get(key)==null){if(this.getSCStoredValuesCount()>=this.maxResponsesToPersist){this.removeOldestEntry()}}
    this.put(key,value)},trimRequest:function(dsRequest){var keyProps=["dataSource","operationType","operationId","textMatchStyle","values","sortBy","startRow","endRow","data"],trimmed={},undef;for(var i=0;i<keyProps.length;i++){if(dsRequest[keyProps[i]]!==undef){trimmed[keyProps[i]]=dsRequest[keyProps[i]]}}
    return trimmed},trimResponse:function(dsResponse){var keyProps=["dataSource","startRow","endRow","totalRows","data","offlineTimestamp","status","errors","invalidateCache","cacheTimestamp"],trimmed={},undef;for(var i=0;i<keyProps.length;i++){if(dsResponse[keyProps[i]]!==undef){trimmed[keyProps[i]]=dsResponse[keyProps[i]]}}
    return trimmed},getResponse:function(dsRequest){var trimmedRequest=this.trimRequest(dsRequest),key=this.serialize(trimmedRequest),value=this.get(key),returnValue;eval('returnValue = '+value);if(returnValue)returnValue.fromOfflineCache=true;return returnValue},serialize:function(obj){return isc.Comm.serialize(obj,false)},showStorageInfo:function(){if(!this.storageBrowser){if(isc.Offline.localStorageType()==isc.Offline.USERDATA_PERSISTENCE){isc.Timer.setTimeout(function(){isc.say("WARNING:  This browser uses an old storage mechanism that does not "+"permit arbitrary key/value pair storage.  This means we have to "+"store extra management data, with the upshot that the metrics reported "+"for 'priority queue' and 'overhead' are indicative, but not accurate")},0)}
    this.metricsDF=isc.DynamicForm.create({width:"100%",numCols:6,fields:[{name:"storedEntries",title:"No. entries",disabled:true},{name:"storedKeyBytes",title:"Used by keys",disabled:true},{name:"storedValueBytes",title:"Used by values",disabled:true},{name:"priorityQueue",title:"Used by Priority Queue",disabled:true},{name:"metricsOverhead",title:"Metrics overhead",disabled:true},{name:"total",title:"Total Bytes",disabled:true}]});this.storageLG=isc.ListGrid.create({width:"100%",height:"*",canRemoveRecords:true,removeData:function(record){isc.ask("Remove this entry?",function(value){if(value){isc.Offline.remove(record.key);isc.Offline.refreshStorageInfo()}})},rowDoubleClick:function(record){isc.Offline.createStorageEditorWindow();isc.Offline.storageEditorWindow.show();isc.Offline.storageEditor.editRecord(record)},fields:[{name:"key",width:"25%",title:"Key"},{name:"value",title:"Value"}]});this.storageBrowser=isc.Window.create({autoCenter:true,canDragResize:true,width:Math.floor(isc.Page.getWidth()*0.5),height:Math.floor(isc.Page.getHeight()*0.5),title:"Offline Storage",items:[this.metricsDF,this.storageLG,isc.HLayout.create({width:"100%",height:1,members:[isc.LayoutSpacer.create({width:"*"}),isc.Button.create({title:"Add Entry",click:function(){isc.Offline.createStorageEditorWindow();isc.Offline.storageEditorWindow.show();isc.Offline.storageEditor.editNewRecord()}})]})]})}
    this.storageBrowser.show();this.refreshStorageInfo()},createStorageEditorWindow:function(){if(!isc.Offline.storageEditorWindow){isc.Offline.storageEditor=isc.DynamicForm.create({fields:[{name:"key",title:"Key",editorType:"TextAreaItem",width:400},{name:"value",title:"Value",editorType:"TextAreaItem",width:400},{name:"saveButton",type:"button",title:"Save",click:function(){var form=isc.Offline.storageEditor;if(form.saveOperationType=="update"&&form.getValue("key")!=form.getOldValue("key"))
    {isc.ask("Key has changed - this will create a new entry. "+"Do you want to retain the old entry as well? (if "+"you answer 'No', it will be removed",function(value){if(value===false){isc.Offline.remove(form.getOldValue("key"))}
    if(value!=null){isc.Offline.put(form.getValue("key"),form.getValue("value"));isc.Offline.storageEditorWindow.hide();isc.Offline.refreshStorageInfo()}})}else{isc.Offline.put(form.getValue("key"),form.getValue("value"));isc.Offline.storageEditorWindow.hide();isc.Offline.refreshStorageInfo()}}}]});isc.Offline.storageEditorWindow=isc.Window.create({bodyProperties:{margin:5},title:"Edit Offline Storage Entry",isModal:true,autoCenter:true,height:280,width:480,items:[isc.Offline.storageEditor]})}},refreshStorageInfo:function(){this.metricsDF.editRecord(isc.Offline.getStorageMetrics());var dataObj=isc.Offline.getCacheContents();var data=[];for(var key in dataObj){data.add({key:key,value:dataObj[key]})}
    this.storageLG.setData(data)}};var UserDataPersistence={isInitialized:false,poolSize:10,keyIndexKey:"keyIndex",reverseKeyIndexKey:"reverseKeyIndex",init:function(){this.userDataSpan=[];for(var i=0;i<this.poolSize;i++){this.userDataSpan[i]=document.createElement('span');this.userDataSpan[i].ID='isc_userData_'+i;this.userDataSpan[i].style.behavior='url(#default#userdata)';document.body.appendChild(this.userDataSpan[i]);this.userDataSpan[i].load("isc_userData_"+i)}
    this.keyIndexStore=document.createElement('span');this.keyIndexStore.ID='isc_userData_keyIndex';this.keyIndexStore.style.behavior='url(#default#userdata)';document.body.appendChild(this.keyIndexStore);this.keyIndexStore.load("isc_userData_keyIndex");this.keyIndex=this.getKeyIndexFromStore();this.reverseKeyIndex=this.getReverseKeyIndexFromStore();if(!this.keyIndex){this.keyIndex={};this.reverseKeyIndex={}}else if(!this.reverseKeyIndex)this.buildReverseKeyIndex();this.buildNextAttributeInfo();this.isInitialized=true},clearCacheNatively:function(){for(var i=0;i<this.poolSize;i++){var attrs=this.userDataSpan[i].xmlDocument.firstChild.attributes;while(attrs.length>0){this.userDataSpan[i].removeAttribute(attrs[0].name)}}
    this.keyIndex={};this.reverseKeyIndex={};this.saveKeyIndex()},getNativeStoredValuesCount:function(){var count=0;for(var i=0;i<this.poolSize;i++){count+=this.userDataSpan[i].xmlDocument.firstChild.attributes.length}
    return count},getKeyForNativeIndex:function(index){var iCounter=0;for(var i=0;i<this.poolSize;i++){if(iCounter+this.userDataSpan[i].xmlDocument.firstChild.attributes.length>index){var offsetIndex=index-iCounter;var attrName=this.userDataSpan[i].xmlDocument.firstChild.attributes[offsetIndex].name,attrNum=attrName.substring(1),dsKey=this.getKeyIndexValue(i,attrNum);return this.getUserKey(dsKey)}}},getKeyIndexValue:function(index,attrName){var attrNum=attrName.substring(1);if(index==0){return"00000".substring(attrNum.length)+attrNum}
    return index*10000+(1*attrNum)},getUserKey:function(userKey){return this.reverseKeyIndex[userKey]},getDataStoreKey:function(key){return this.keyIndex[key]},$70p:function(dataStore,attr){return this.userDataSpan[dataStore].getAttribute(attr)},getValue:function(userKey){var key=this.getDataStoreKey(userKey),undef;if(key===undef)return null;var dataStore=(""+key).substring(0,1),attr="v"+((""+key).substring(1)*1);return this.$70p(dataStore,attr)},putValue:function(userKey,value){var key=this.getDataStoreKey(userKey);if(key){var dataStore=(""+key).substring(0,1),attr="v"+((""+key).substring(1)*1),savedValue=this.$70p(dataStore,attr)}else{var dataStore=this.getDataStoreForNewItem(),attr=this.getNextAttributeName(dataStore)}
    this.userDataSpan[dataStore].setAttribute(attr,value);try{this.userDataSpan[dataStore].save("isc_userData_"+dataStore);this.addToKeyIndex(userKey,dataStore,attr)}catch(e){if(isc.Offline.isStorageException(e)){if(savedValue){this.userDataSpan[dataStore].setAttribute(attr,savedValue)}else{this.userDataSpan[dataStore].removeAttribute(attr);this.removeFromKeyIndex(userKey)}}
    throw e}},removeValue:function(userKey){var key=this.getDataStoreKey(userKey),undef;if(key===undef){Offline.logWarn("userData: in removeValue, no value for key '"+userKey+"' was found");return}
    var dataStore=(""+key).substring(0,1),attr="v"+((""+key).substring(1)*1);this.userDataSpan[dataStore].removeAttribute(attr);this.userDataSpan[dataStore].save("isc_userData_"+dataStore);this.removeFromKeyIndex(userKey);this.unusedAttributeNumbers[dataStore].push(attr.substring(1)*1)},getDataStoreForNewItem:function(){var undef;if(this.nextDataStoreToUse===undef){this.nextDataStoreToUse=Math.floor(Math.random()*this.poolSize)}
    var rtnValue=this.nextDataStoreToUse++;if(this.nextDataStoreToUse>=this.poolSize)this.nextDataStoreToUse=0;return rtnValue},
    buildNextAttributeInfo: function () {
        this.nextAttributeNumber=[];
        this.unusedAttributeNumbers=[];
        for(var i=0;i<this.poolSize;i++){
            this.unusedAttributeNumbers[i]=[];
            var attrs=this.userDataSpan[i].xmlDocument.firstChild.attributes;
            var work=[];
            for(var j=0;j<attrs.length;j++){
                var num=attrs[j].name.substring(1)*1;
                if(!isNaN(num))work.add(attrs[j].name.substring(1)*1)
            }
            if(work.sort)work.sort();
            else this.sort(work);
            var counter=0;
            for(j=0;j<work.length;j++){
                if(work[j]==counter){
                    counter++;
                    continue;
                }
                while(work[j]!=counter&&counter<=9999){
                    this.unusedAttributeNumbers[i].push(counter++)
                }
                counter++;
            }
            this.nextAttributeNumber[i]=counter
        }
    },
    sort:function(array){for(var i=0;i<array.length;i++){var swapped=false;for(var j=1;j<array.length-i;j++){if(array[j]<array[j-1]){var temp=array[j];array[j]=array[j-1];array[j-1]=temp;swapped=true}}
    if(!swapped)break}},getNextAttributeName:function(dataStore){if(this.unusedAttributeNumbers[dataStore]&&this.unusedAttributeNumbers[dataStore].length>0)
    {return"v"+this.unusedAttributeNumbers[dataStore].shift()}
    if(this.nextAttributeNumber[dataStore]==null){this.nextAttributeNumber[dataStore]=1}
    return"v"+this.nextAttributeNumber[dataStore]++},addToKeyIndex:function(userKey,dataStore,attr){var keyIndexValue=this.getKeyIndexValue(dataStore,attr);this.keyIndex[userKey]=keyIndexValue;this.reverseKeyIndex[keyIndexValue]=userKey;this.saveKeyIndex()},removeFromKeyIndex:function(userKey){var keyIndexValue=this.keyIndex[userKey];delete this.keyIndex[userKey];delete this.reverseKeyIndex[keyIndexValue];this.saveKeyIndex()},saveKeyIndex:function(){this.keyIndexStore.setAttribute(this.keyIndexKey,Offline.serialize(this.keyIndex));this.keyIndexStore.setAttribute(this.reverseKeyIndexKey,Offline.serialize(this.reverseKeyIndex));this.keyIndexStore.save("isc_userData_keyIndex")},buildReverseKeyIndex:function(){this.reverseKeyIndex={};for(var key in this.keyIndex){this.reverseKeyIndex[keyIndex[key]]=key}},getKeyIndexFromStore:function(){var kiText=this.keyIndexStore.getAttribute(this.keyIndexKey);if(kiText){eval("var ki = "+kiText)}else{var ki=null}
    return ki},getReverseKeyIndexFromStore:function(){var kiText=this.keyIndexStore.getAttribute(this.reverseKeyIndexKey);if(kiText){eval("var ki = "+kiText)}else{var ki=null}
    return ki}};
    
    if(window.isc){isc.defineClass("Offline").addClassProperties(Offline);isc.defineClass("UserDataPersistence").addClassProperties(UserDataPersistence)}else{isc.addProperties=function(objOne,objTwo){for(var propName in objTwo)objOne[propName]=objTwo[propName]}
    isc.addProperties(isc.Offline,{serialize:function(object){return isc.OfflineJSONEncoder.encode(object)},logWarn:function(message){if(console)console.log(message)},logError:function(message){if(console){console.log(message)}else{alert(message)}},echoLeaf:function(obj){var output="",undefined;if(obj===undefined)return"undef";try{if(typeof obj=="Array"){output+="Array["+obj.length+"]"}else if(typeof obj=="Date"){output+="Date("+obj.toShortDate()+")"}else if(typeof obj=="Function"){output+=isc.Func.getName(obj,true)+"()"}else{switch(typeof obj){case"string":if(obj.length<=40){output+='"'+obj+'"';break}
    output+='"'+obj.substring(0,40)+'..."['+obj.length+']';output=output.replaceAll("\n","\\n").replaceAll("\r","\\r");break;case"object":if(obj==null){output+="null";break}
    if(obj.tagName!=null){output+="["+obj.tagName+"Element]";break}
    var toString=""+obj;if(toString!=""&&toString!="[object Object]"&&toString!="[object]")
    {output+=toString;break}
    output+="Obj";break;default:output+=""+obj}}
    return output}catch(e){var message="[Error in echoLeaf: "+e+"]";output+=message;return output}},echo:function(object){return this.serialize(object)}});isc.OfflineJSONEncoder={$zm:function(objRefs,object,path){objRefs.obj.add(object);objRefs.path.add(path)},$42b:function(object){var treeId=object["$42c"];if(treeId!=null){var theTree=window[treeId];if(theTree&&theTree.parentProperty&&object[theTree.parentProperty]){object=theTree.getCleanNodeData(object)}}
    return object},$zl:function(objRefs,object){var rowNum=objRefs.obj.indexOf(object);if(rowNum==-1)return null;return objRefs.path[rowNum]},$zp:function(objPath,newIdentifier){if(isc.isA.Number(newIdentifier)){return objPath+"["+newIdentifier+"]"}else if(!isc.Comm.$zk.test(newIdentifier)){return objPath+'["'+newIdentifier+'"]'}else{return objPath+"."+newIdentifier}},encode:function(object){this.objRefs={obj:[],path:[]};var retVal=this.$eu(object,this.prettyPrint?"":null,null);this.objRefs=null;return retVal},dateFormat:"xmlSchema",encodeDate:function(date){if(this.dateFormat=="dateConstructor"){return"new Date("+date.getTime()+")"}else{return'"'+this.toSchemaDate(date)+'"'}},toSchemaDate:function(date){var dd=""+date.getDate(),mm=""+(date.getMonth()+1),yyyy=""+(date.getyear()+1900),hh=""+date.getHours(),mi=""+date.getMinutes(),ss=""+date.getSeconds();dd=dd.length==1?"0"+dd:dd;mm=mm.length==1?"0"+mm:mm;hh=hh.length==1?"0"+hh:ff;mi=mi.length==1?"0"+mi:mi;ss=ss.length==1?"0"+ss:ss;return yyyy+"-"+mm+"-"+dd+"T"+hh+":"+mi+":"+ss},strictQuoting:true,circularReferenceMode:"path",circularReferenceMarker:"$$BACKREF$$",prettyPrint:false,$eu:function(object,prefix,objPath){if(!objPath){if(object&&object.getID)objPath=object.getID();else objPath=""}
    if(object==null)return null;if(this.isAString(object))return this.asSource(object);if(this.isAFunction(object))return null;if(this.isANumber(object)||this.isASpecialNumber(object))return object;if(this.isABoolean(object))return object;if(this.isADate(object))return this.encodeDate(object);if(this.isAnInstance(object))return null;var prevPath=this.$zl(this.objRefs,object);if(prevPath!=null&&objPath.contains(prevPath)){var nextChar=objPath.substring(prevPath.length,prevPath.length+1);if(nextChar=="."||nextChar=="["||nextChar=="]"){var mode=this.circularReferenceMode;if(mode=="marker"){return"'"+this.circularReferenceMarker+"'"}else if(mode=="path"){return"'"+this.circularReferenceMarker+":"+prevPath+"'"}else{return null}}}
    if(this.isAClassObject(object))return null;if(object==window)return null;this.$zm(this.objRefs,object,objPath);if(this.isAFunction(object.$eu)){return object.$eu(prefix,this.objRefs,objPath)}
    if(this.isAnArray(object)){return this.$zn(object,objPath,this.objRefs,prefix)}
    var data;if(object.getSerializeableFields){data=object.getSerializeableFields([],[])}else{data=object}
    return this.$zo(data,objPath,this.objRefs,prefix)},$zn:function(object,objPath,objRefs,prefix){var output="[";for(var i=0,len=object.length;i<len;i++){var value=object[i];if(prefix!=null)output+="\r"+prefix;var objPath=this.$zp(objPath,i);var serializedValue=this.$eu(value,(prefix!=null?prefix:null),objPath);output+=serializedValue+",";if(prefix!=null)output+=" "}
    var commaChar=output.lastIndexOf(",");if(commaChar>-1)output=output.substring(0,commaChar);if(prefix!=null)output+="\r"+prefix;output+="]";return output},$zo:function(object,objPath,objRefs,prefix){var output="{",undef;object=this.$42b(object);try{for(var key in object)break}catch(e){return null}
    for(var key in object){if(key==null)continue;if(key=="xmlHttpRequest")continue;if(key.substring(0,1)=="_"||key.substring(0,1)=="$")continue;var value=object[key];if(this.isAFunction(value))continue;if(this.isAnInstance(value))continue;var keyStr=key.toString();keyStr='"'+keyStr+'"';var objPath=this.$zp(objPath,key);var serializedValue;if(key!="__ref"){serializedValue=this.$eu(value,(prefix!=null?prefix:null),objPath)}
    if(prefix!=null)output+="\r"+prefix;output+=keyStr+":"+serializedValue+",";if(prefix!=null)output.append(" ")}
    var commaChar=output.lastIndexOf(",");if(commaChar>-1)output=output.substring(0,commaChar);if(prefix!=null)output+="\r"+prefix;output+="}";return output},isAString:function(object){if(object==null)return false;if(typeof object==this.$a7)return false;if(object.constructor&&object.constructor.$k!=null){return object.constructor.$k==4}
    if(object.Class!=null&&object.Class==this.$73x)return true;return typeof object=="string"},isAnArray:function(object){if(object==null)return false;if(typeof object==this.$a7)return false;if(object.constructor&&object.constructor.$k!=null){return object.constructor.$k==2}
    if(isc.Browser.isSafari)return""+object.splice=="(Internal function)";return""+object.constructor==""+Array},isAFunction:function(object){if(object==null)return false;if(isc.Browser.isIE&&typeof object==this.$a7)return true;var cons=object.constructor;if(cons&&cons.$k!=null){if(cons.$k!=1)return false;if(cons===Function)return true}
    return isc.Browser.isIE?(isc.emptyString+object.constructor==Function.toString()):(typeof object==this.$a7)},isANumber:function(object){if(object==null)return false;if(object.constructor&&object.constructor.$k!=null){if(object.constructor.$k!=5)return false}else{if(typeof object!="number")return false}
    return!isNaN(object)&&object!=Number.POSITIVE_INFINITY&&object!=Number.NEGATIVE_INFINITY},isASpecialNumber:function(object){if(object==null)return false;if(object.constructor&&object.constructor.$k!=null){if(object.constructor.$k!=5)return false}else{if(typeof object!="number")return false}
    return(isNaN(object)||object==Number.POSITIVE_INFINITY||object==Number.NEGATIVE_INFINITY)},isABoolean:function(object){if(object==null)return false;if(object.constructor&&object.constructor.$k!=null){return object.constructor.$k==6}
    return typeof object=="boolean"},isADate:function(object){if(object==null)return false;if(object.constructor&&object.constructor.$k!=null){return object.constructor.$k==3}
    return(""+object.constructor)==(""+Date)&&object.getDate&&isc.isA.Number(object.getDate())},isAnXMLNode:function(object){if(object==null)return false;if(isc.Browser.isIE){return object.specified!=null&&object.parsed!=null&&object.nodeType!=null&&object.hasChildNodes!=null}
    var doc=object.ownerDocument;if(doc==null)return false;return doc.contentType==this.$bm},isAnInstance:function(object){return(object!=null&&object.$76y!=null)},isAClassObject:function(object){return(object!=null&&object.$bp==true)},asSource:function(string,singleQuote){if(!this.isAString(string))string=""+string;var quoteRegex=singleQuote?String.$ez:String.$e0,outerQuote=singleQuote?"'":'"';return outerQuote+string.replace(/\\/g,"\\\\").replace(quoteRegex,'\\'+outerQuote).replace(/\t/g,"\\t").replace(/\r/g,"\\r").replace(/\n/g,"\\n")+outerQuote}}}})();
        } else {
            isc.Log.logWarn("Patch for SmartClient 8.0 final release (reported version " +
                "'SC_SNAPSHOT-2011-01-05' or 'SC_SNAPSHOT-2011-01-06') " +
                "included in this application. " + 
                "You are currently running SmartClient version '"+ isc.version + 
                "'. This patch is not compatible with this build and will have no effect. " +
                "It should be removed from your application source.");
        }
    }
    Note: This patch is also required for SmartGWT 2.4, which has the same underlying SmartClient JavaScript code. To apply the patch code to a SmartGWT application, simply add a <script> block containing the above code to the bootstrap HTML file under your war directory, after the <script src=applicationname/applicationname.nocache.js></script> block.
Working...
X