How can you report or display an error from an XSP.partialRefreshPost call

天大地大妈咪最大 提交于 2019-12-25 05:09:52

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!