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):
table.getErrorCode = function(){
var responseCode = this._http.status;
return responseCode == 200 ? 0 : responseCode;
}
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).
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)
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:
obj.setErrorProperty("code", function(){
return this.getDataProperty("errorCode");
});
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.