Reputation: 1154
I have one jqGrid where I am doing Form Editing. Getting options with below values.
$("#usergrid").jqGrid('navGrid',"#usergridpager",{add:true,edit:true,del:false,search:false,refresh:true},{},{},{}}
I want some error message if there is anything wrong happens while adding data into DB. I tried with
// add options
{closeAfterAdd:true,
closeOnEscape:true,
url: "adddata.html",
recreateForm:true,
afterSubmit : function(response, postdata) {
return [false, response.responseText, ""];
// Tried with return [true, response.responseText, ""]; and few more
}
},{}
I am trying to insert existing data(primary key collision) so that I could test above method but not getting any message on display. But server console is getting proper failed log. Instead at the top of popup window I get
"error Status: 'Internal Server Error'. Error code: 500"
How to customize these messages and show them in little user friendly form.
Update - the value in URL attribute is mapped with one Spring MVC's Controller in my java code which is actually doing all insert/update.
Upvotes: 1
Views: 2676
Reputation: 1154
If you want to show server error in UI with proper message then we do not need to handle any kind of excpetion in our java code. Just let it come to UI. Write something like below code
{closeAfterAdd:true, closeOnEscape:true, url: "adddata.html",recreateForm:true,
beforeShowForm: function(form) {
$('#tr_userId', form).show();
},errorTextFormat : function(data){
if (data.status == 500)
return data.responseText; //Little HTML parsing you'll have to do
}// add options
}
Upvotes: 1
Reputation: 221997
The callback afterSubmit
will be called in case of receiving successful response at the end of form editing. If HTTP request to save data failed then errorTextFormat
callback will be processed.
It's recommended additionally to use exception handles inside of server code. It allows mostly to produce more readable error as "Internal Server Error. Error code: 500". It's typically that the exception during database operations contains more information. One can catch such exceptions and return a readable error back to the client.
You should change the code of afterSubmit
so that you distinguish successful saving from non-successful. The current code returns allways return [false, ...]
so jqGrid will never end of editing.
Upvotes: 2