PDA

View Full Version : Reading response message from Servlet in EXT.FormPanel to display success or failure



n_subram
15 May 2012, 2:54 PM
Hello,

I am using ExtJS 3.4

From my servlet I am sending success , failure messages as below.[SIZE=2]For Success:
PrintWriter out = null;
response.setContentType("text/html");
out = response.getWriter();
out.println("{\"success\":true, \"msg\":\"success\"}"); For Failure:
PrintWriter out = null;
response.setContentType("text/html");
out = response.getWriter();
out.println("{\"success\":false, \"msg\":\"" + failureMessage + "\"}")
failureMessage may contain the value as below
{"success":false, "msg":"Invilid Account Number."}
From Ext.FormPanel I want to read these messages and display the text in a alert box.
Ext.Msg.alert("Invilid Account Number.");
But even in case of the error I am getting success message.
Can you please help to read the messages I am sending throught my servlet.
Thanks a lot !
My FormPanel Code looks like below:


myPanel = new Ext.FormPanel({
id: "myPanel",
fileUpload: true,
layout: 'form',
border: false,
width: '100%',
items: [{
xtype: 'textfield',
id: 'accountNbr',
fieldLabel: '*Enter Account',
allowBlank: false
}, {
xtype: 'fileuploadfield',
width: 400,
id: 'pacProcessingFileuploadfield',
allowBlank: false
}],
buttonAlign: 'left',
buttons: [{
text: 'Upload',
handler: function() {

if (myPanel.getForm().isValid()) {
var params = {
environment: local,
standardId: standardId,
process: "packageProcessing"
};
myPanel.getForm().submit({
headers: {
'Content-Type': "multipart/form-data",
'Accept': "text/plain"
},
method: 'POST',
url: http: //localhost:9080/fileupload? + Ext.urlEncode(params),
waitMsg: 'Uploading your file...',
success: function(form, action) {
if (action.success) {
Ext.Msg.alert("Document Uploaded successfully.");
} else {
Ext.Msg.alert("Failed to upload document.");
}
},
failure: function(form, action) {
switch (action.failureType) {
case Ext.form.Action.CLIENT_INVALID:
Ext.Msg.alert('Failure', 'Form fields may not be submitted with invalid values');
break;
case Ext.form.Action.CONNECT_FAILURE:
Ext.Msg.alert('Failure', 'Ajax communication failed');
break;
case Ext.form.Action.SERVER_INVALID:
//Ext.Msg.alert('Failure', action.result.msg);
Ext.Msg.alert(CitadelExtJsUI.Application.appName, "Failed to upload documents.");
}
}

}); //submit method end
} // form validation end
}

}]
});

scottmartin
17 May 2012, 9:01 AM
Please review the action parameter for submit:
extjs4/docs/#!/api/Ext.form.action.Submit

Check for action.result
console.log(action)

Regards,
Scott.