Showing posts with label bugfix. Show all posts
Showing posts with label bugfix. Show all posts

Monday, October 11, 2010

XPages: Another bugfix for the partial refresh hijacker

When the onStart/-Complete/-Error code for an event was served to the browser as a string, it wouldn't run. This bug has now been fixed.

Original post with code

Friday, May 7, 2010

XPages: Severe bug in the partial event hijacker

Update 11.10.2010 Found another bug. onComplete can sometimes be a string. Fixed.

For the life of me, I couldn't understand why the onStart/onError/onComplete events didn't fire for partial refreshes. Today it suddenly dawned on me. It was because of my partial event hijacker.

The previous version overwrote the onStart/onError/onComplete events. Below is the fixed code. Sorry if you've used the hijacker and suffered the same fate as me.

function hijackAndPublishPartialRefresh(){
// Hijack the partial refresh
XSP._inheritedPartialRefresh = XSP._partialRefresh;
XSP._partialRefresh = function( method, form, refreshId, options ){
// Publish init
dojo.publish( 'partialrefresh-init', [ method, form, refreshId, options ]);
this._inheritedPartialRefresh( method, form, refreshId, options );
}

// Publish start, complete and error states
dojo.subscribe( 'partialrefresh-init', function( method, form, refreshId, options ){
if( options ){ // Store original event handlers
var eventOnStart = options.onStart;
var eventOnComplete = options.onComplete;
var eventOnError = options.onError;
}

options = options || {};
options.onStart = function(){
dojo.publish( 'partialrefresh-start', [ method, form, refreshId, options ]);
if( eventOnStart ){
if( typeof eventOnStart === 'string' ){
eval( eventOnStart );
} else {
eventOnStart();
}
}
};

options.onComplete = function(){
dojo.publish( 'partialrefresh-complete', [ method, form, refreshId, options ]);
if( eventOnComplete ){
if( typeof eventOnComplete === 'string' ){
eval( eventOnComplete );
} else {
eventOnComplete();
}
}
};

options.onError = function(){
dojo.publish( 'partialrefresh-error', [ method, form, refreshId, options ]);
if( eventOnError ){
if( typeof eventOnError === 'string' ){
eval( eventOnError );
} else {
eventOnError();
}
}
};
});
}