问题
I am using custom event handlers for many parts of our application. Tim Tripcony describes this in his blog... He will, most likely (hopefully) answer this...
The event handlers in my code look like this:
<xp:eventHandler
id="newbsDoSomething"
submit="true"
event="calledbyid"
refreshMode="complete">
<xp:this.action>
<![CDATA[#{javascript:doSomethingFromSomewhere();}]]>
</xp:this.action>
</xp:eventHandler>
The buttons or other controls execute these events with code that look like this:
XSP.partialRefreshPost(("#{id:newbsDoSomething}", {
params : {
'$$xspsubmitvalue' : 'something that tells it what to do.'
},
onError : function(err) {
alert('Whatever this method is doing got an error...');
//I want to report the error here
},
onComplete : function() {
// maybe do something else
})
});
When I make a mistake (once in a blue moon) and the response to the AJAX request contains a stack trace. I want to put up a button that optionally renders the stack trace in another page.
In the onError method the err is undefined, so that is not helping. I do not see a property of the XSP object that would contain the response. I can see the response in the Firebug console, but how would I get it pragmatically?
/Newbs
回答1:
The problem is that the CSJS function XSP._partialRefresh checks if the onError-parameter is a function or not. if it is a function, it is called w/o the required parameters.
But if you use a string instead, a eval is done with it, so it would be possible to do something like this:
function myErrHandler(){
// just do some debugging
// of ioArgs object
var arg = arguments[1];
var txt = "";
for( p in arg ){
txt += p + " -> " + arg[p] + " [" + typeof( arg[p] ) + "]\n";
}
alert( txt );
}
XSP.partialRefreshPost("#{id:newbsDoSomething}", {
onError : 'myErrHandler( arguments[0], arguments[1] )'
});
Hope this helps
Sven
来源:https://stackoverflow.com/questions/11402658/how-can-you-report-or-display-an-error-from-an-xsp-partialrefreshpost-call