3.0.5

Error Handling grid

Hi,

I have a question on error handling in the Grid Control. Data in my grid is generated, however when there is an error the data returned is not xml and relates to the specific error that occured. In such a case the XML parsing in the grid fails and the grid displays the message "no data loaded". I would like to display the message that was returned to the user. Any suggestions on how this can be implemented?


Thanks
Bhaskar
September 16,
Hi Alex,

Since error handling is a requirement for our use of the Grid I would really appreciate any suggestions you might have.

I was thinking that overriding the response method and providing some information would be a possible solution

I came up with this initial solution

if (!window.Prima) Prima=[]; 
if (!Prima.XML) Prima.XML=[]; 

Prima.XML.Table = Active.XML.Table.subclass(); 

Prima.XML.Table.create = function() 
{
    var obj = this.prototype;
    var _super = this.superclass.prototype;

    // define a response for the table
    var defaultResponse = _super.response;

    obj.response = function(xml)
    {
        var responseCode = this._http.status;
        if(responseCode == 200)
        {
            defaultResponse.call(this,xml);
        }
        else if(responseCode >= 400 && responseCode < 500)
        {
            alert("<bean:message key='error.httpclientresponseerror'/>" + this._http.status);
            defaultResponse.call(this, xml);
        }
        else if(responseCode >=500 && responseCode < 600)
        {
            alert("<bean:message key='error.httpserverresponseerror'/>" + this._http.status);
            defaultResponse.call(this, xml);
        }
        else
        {
            alert("<bean:message key='error.httpnetworkerror'/>" + this._http.status);
            defaultResponse.call(this, xml);
        }
    }
}; 

Prima.XML.Table.create();


However I would like to use something better than an alert statement to achieve this; preferable a popup providing detailes message.

Would this be a feasible solution?


Thanks
Bhaskar
September 19,
Hi Bhaskar,

I had in mind something slightly different:

First, you have to enhance the table model with error code and error message properties (I skip creating subclass for simplicity):

// define error codes
table.getErrorCode = function(){
    var responseCode = this._http.status;
    return responseCode == 200 ? 0 : responseCode;
}

// define error messages
table.getErrorText = function(){

    var errorCode = this.getErrorCode();

    if(errorCode >= 400 && errorCode < 500) {
        return "<bean:message key='error.httpclientresponseerror'/>" + errorCode;
    }
    else if(errorCode >=500 && errorCode < 600) {
        return "<bean:message key='error.httpserverresponseerror'/>" + errorCode;
    }
    else {
        return "<bean:message key='error.httpnetworkerror'/>" + errorCode;
    }
}


Then you also have to modify grid's status/code property, which collects all status data into the single code (assuming that data model is not the only possible source of errors).

//	status code
obj.setStatusProperty("code", function(){
    var data = this.getDataModel();
    if (!data.isReady()) {
        return "loading";
    }
    if (data.getErrorCode()) {
        return "error";
    }
    if (!this.getRowProperty("count")) {
        return "nodata";
    }
    return "";
});


This is necessary to activate the template switching logic. Here is the default code, you can keep it as is (part of grid object)

// define custom template logic
obj.setTemplate("main", function(){

    switch (this.getStatusProperty("code")) {
        case "":
            return this.getDataTemplate();

        case "error":
            return this.getErrorTemplate();

        default:
            return this.getStatusTemplate();
    }
});


The default error template will show error/text and error/code properties, so you at least have to redirect them to the new data model properties:

// define custom error codes
obj.setErrorProperty("code", function(){
    return this.getDataProperty("errorCode");
});

// define custom error messages
obj.setErrorProperty("text", function(){
    return this.getDataProperty("errorText");
});


The default error template is defined in Active.Templates.Error class. You can replace it with your own:

obj.setTemplate("error", myErrorTemplate);


Similar logic applies to the status codes and status template, for example "Loading, please wait.." message.
Alex (ActiveWidgets)
September 19,
Thanks Alex, really appreciate it
Bhaskar
September 20,

This topic is archived.

See also:


Back to support forum