Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Error Function to XPages Partial Refresh (dojo.xhrPost) Events?

I have a page which depends a number of partial refreshes for interaction. I'm not looking to use a keep session alive mechanism, but I would like to catch error responses to my partial refreshes, alert the user that their session expired / they need to refresh, perform a window.location.reload once they've acknowledged the alert. Specifically, to be event-driven by the user's attempt at a partial refresh (and, by nature, purely through CSJS).

I know from using Chrome DevTools that the partial refresh shows as a Post request, which returns the partial (refresh area) of the html plus any requisite CSJS. I also know that, as documented under Dojo 1.6 in regards to dojo.xhr (Post and Get) supports an error handling parameter, by which I can pass the function I'll want to create. I'm currently uncertain of how to add this function to my dojo.xhrPost requests.

Having seen this XSnippet, "Cache Prevention for Dojo xhr requests", which allows for adding the preventCache option to dojo.xhr requests, I feel this is the right approach. Again, it's the implementation I'm uncertain of. I was disappointed to find that the link it referenced as the source, http://www.juliusbuss.de/web/youatnotes/blog-jb.nsf/dx/a-big-issue-for-mobile-web-apps-with-xpages-for-iphone-and-ipad-and-how-to-solve-it..htm, was not working for me.

  1. I'm uncertain of whether I can use the same argument, arguments[1], as in the referenced XSnippet (or which is the best arguments position).
  2. Also, I'm not 100% sure of whether I need to further specify this for dojo xhrPost events, or if just using the dojo.xhr is good enough.

Would love a more experienced perspective.

like image 417
Eric McCormick Avatar asked Jul 19 '26 12:07

Eric McCormick


1 Answers

Here is an example how to override the error function for every partialRefresh:

// hijack the dojo function if required
if( !dojo._xhr )
    dojo._xhr = dojo.xhr;

var _error;

dojo.xhr = function(){       
    try{
        var args = arguments[1];  
        _error = args["error"]; // save the original error function

        // add your own method
        args["error"] = function(arg1, arg2){
            alert( "Hello World!" );
            _error(arg1, arg2);
        }
        arguments[1] = args;
    }catch(e){}
    dojo._xhr( arguments[0], arguments[1], arguments[2] );
}
like image 145
Sven Hasselbach Avatar answered Jul 22 '26 02:07

Sven Hasselbach



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!