Thursday, March 8, 2012

Patch for bug in XSP.partialRefreshGet/-Post in 8.5.3

Someone made a really stupid mistake in the code for XSP.partialRefreshGet/-Post in 8.5.3..

I won't go into specifics of the code as I'm uncertain if it's breaking some license. Let's just say that if they moved a line of code four or five lines upwards, there wouldn't be any bug.

I wrote a simple patch for the bug. Put it in a CSJS library, and your code will work like it did on 8.5.2 (unless I made a stupid mistake).

/**
* Fix for bug with partialRefreshGet/-Post in 8.5.3
*/
(function(){
var oldPartialRefreshGet = XSP.partialRefreshGet;
XSP.partialRefreshGet = function( targetId, options ){
// Convert to array
var argsArray = Array.prototype.slice.apply( arguments );

if( argsArray.length > 1 ){ argsArray[1] = argsArray[1] || {}; }
if( argsArray.length === 1 ){ argsArray.push( {} ); }

oldPartialRefreshGet.apply( XSP, argsArray );
};

var oldPartialRefreshPost = XSP.partialRefreshPost;
XSP.partialRefreshPost = function( targetId, options ){
// Convert to array
var argsArray = Array.prototype.slice.apply( arguments );

if( argsArray.length > 1 ){ argsArray[1] = argsArray[1] || {}; }
if( argsArray.length === 1 ){ argsArray.push( {} ); }

oldPartialRefreshPost.apply( XSP, argsArray );
};
})();


This code should be forwards compatible with future API updates, as it doesn't assume number of arguments in function.

11 comments:

Fredrik said...

Do you mean the problem that a parameter is required in 8.5.3?

Anonymous said...

@Frederik: yep, the code seems to fix this. You can use XSP.partialRefreshGet("#{id:col1}"); in 8.5.3 then.

Sven Hasselbach said...

@Fredrik:
This seems to fix the "parameter"-problem.

Tommy Valand said...

@Fredrik: A second parameter is needed due to a bug in the code.

There is code that allows for no options parameter (the second parameter), but it's placed after a property is read from options. Hence if no options parameter is specified, the function tries to read a property from undefined -> code crashes.

The code I posted patches this bug.

Erik Brooks said...

Did you open an SPR? I can if you didn't.

Tommy Valand said...

I haven't. If you could, thanks.

Henry said...

Thank you! I have spent allmost 2 days trying to find out what was wrong. I nearly gave up, until I found your blogpost. It works !

Sam Johnson said...

Thanks! This was a big help.

Eltaka said...

Thanks much !

Tommy Valand said...

If you read the blogpost carefully, you can see that it's supposed to be put in a CSJS library. That is to say a Javascript library for the client/browser.

Olle said...

Really, really thanks. You saved my sanity