Sto utilizzando jqGrid
per mostrare i dati in formato tabulare, utilizzando JSP
e servlet
.jqgrid come mostrare i messaggi lato server
EDIT
voglio mostrare gli errori da server, quando vengono eseguite operazioni come insert, update, delete
. (datatype: "xml")
jqGrid
jQuery("#list10_d").jqGrid({
height:250,
width:600,
url:'Assignment?action=Assign',
datatype: "xml",
colNames:['Sr. No.','PID', 'DATE', 'EMPID'],
colModel:[{name:'srNo',index:'srNo', width:30,sortable:false},
{name:'PID',index:'PID',width:0, sortable:true,editable:false},
{name:'DATE',index:'DATE', width:75,sortable:true,editable:true,editoptions: { dataInit: function(el) { setTimeout(function() { $(el).datepicker({dateFormat:"dd-M-yy",showButtonPanel: true,changeYear: true,changeMonth: true}).attr('readonly','readonly'); }, 200); }}},
{name:'EMPID',index:'EMPID', width:150,sortable:true,editable:true}
],
rowNum:10,
rowList:[10,20,50,100],
pager: '#pager10_d',
sortname: 'PID',
viewrecords: true,
sortorder: "asc",
},
multiselect: true,
editurl: "Assignment?action=Edit",
caption:"Assignment"
}).navGrid('#pager10_d',{edit:false,add:true,del:false,addtext:'Assign '},
{},
{modal:true,jqModal: false,closeOnEscape:true,savekey: [true,13],closeOnEscape:true, recreateForm: true,width:500,mtype:'POST', url: 'Assignment',editData:{action: 'Assign',PID: function() {return PID;}},
afterSubmit: function (response) {
alert('After Submit \n' +'statusText: '+ response.statusText);
var myInfo = '<div class="ui-state-highlight ui-corner-all">'+
'<span class="ui-icon ui-icon-info" ' +
'style="float: left; margin-right: .3em;"></span>' +
response.statusText + 'Inserted'+
'</div>',
$infoTr = $("#TblGrid_" + $.jgrid.jqID(this.id) + ">tbody>tr.tinfo"),
$infoTd = $infoTr.children("td.topinfo");
$infoTd.html(myInfo);
$infoTr.show();
// display status message to 3 sec only
setTimeout(function() {
$infoTr.slideUp("slow");
}, 5000);
return [true, "", ""]; // response should be interpreted as successful
},
errorTextFormat: function (response) {
alert('Error Text Format: \n' +'statusText: '+ response.statusText);
return '<span class="ui-icon ui-icon-alert" ' +
'style="float:left; margin-right:.3em;"></span>' +
response.statusText;},
{closeOnEscape:true, recreateForm: true,mtype: 'POST',url: 'Assignment',delData: {action: 'Delete',PID: function() {return PID;}}},
{}) ;
Servlet Codice
if(request.getParameter("action").equalsIgnoreCase("Assign"))
{
PID = request.getParameter("PID");
String DATE= request.getParameter("DATE");
String EMPID= request.getParameter("EMPID");
String query = "insert into ASSIGN(PID,DATE,EMPID) values('"+ PID +"','"+ DATE +"','"+ EMPID"')";
boolean b = insert.InsertData(query);
if(b)
{
System.out.println("New record added successfully! : "+query);
response.setContentType("text/xml");
response.setCharacterEncoding("UTF-8");
//response.sendError(200, "success");
response.setStatus(200, "Inserted successfully");
}
else
{
System.out.println("Failed to add Record! : "+query);
response.setContentType("text/xml");
response.setCharacterEncoding("UTF-8");
//response.sendError(399, "not Inserted successfully");
response.setStatus(404, "Error while inserting");
}
}//INSERT
per esempio precedente
- dopo
inserting
record da jqGrid, poiNo message is shown
nella griglia se il record èinserted successfully
error Status: 'Unauthorized'. Error code: 401
viene visualizzato se il servlet non riesce a inserire record nel database.
mia domanda è che:
- dopo
inserting
record da jqGrid, se il record viene inserito allora come devo mostrare un messaggio di fornire le informazioni di utente che si inserisce i dati. - e come dovrei dare messaggio a utente che
Error while inserting
(cheerror code
devo usare per questo?)
Grazie in anticipo .....
grazie per la risposta (e +1), ci proverò oggi. – Bhushan
@Bhushan: prego! – Oleg
Ho aggiornato la mia domanda, dopo aver implementato il tuo codice, ora i messaggi sono mostrati in cima al modulo come mostrato nell'immagine, ma vengono mostrati solo i codici di stato, come quando sono inseriti con successo solo 'OK' è mostrato, e quando non è stato inserito quindi viene mostrato solo 'Not Found', ma non sono in grado di mostrare il messaggio' custom' inviato dal servlet in forma .. sto facendo un errore durante l'invio dell'errore da servlet in grid? ogni aiuto sarà apprezzato ... – Bhushan