Tina G
29 Oct 2007, 1:21 AM
I have a form that submits to the server. On error: the server has to show the error on the same form.
The following .js file handles form submit:
function doAdd(){
var startIndex=paging.cursor;
var aAddInstanceDlg;
if (!aAddInstanceDlg) {
aAddInstanceDlg = createNewDialog("a-addInstance-dlg");
aAddInstanceDlg.addButton('Reset', resetForm, aAddInstanceDlg);
aAddInstanceDlg.addButton('Save', function() {
// submit now... all the form information are submit to the server
// handle response after that...
if (form_instance_create.isValid()) {
form_instance_create.submit({ // problem here
// params:{prompt_id : editId, prompt_text: text_edit.getValue(), file: engPrompt_edit.getValue()},
params:{prompt_file: engPrompt_tf.getValue()},
waitMsg:'Adding new prompt now...',
reset: false,
failure: function(form_instance_create, action) {
//TBD: Ext.MessageBox.alert('Error Message', action.result.errorInfo);
//remove following 3 lines
//Ext.MessageBox.alert('Confirm', action.result.info);
var errorMsg='<% = (String)request.getSession().getAttribute("error")%>';
alert('error : '+errorMsg);
Ext.MessageBox.alert('Error Message', action.txt);
//aAddInstanceDlg.hide();
prompt_ds.load({params:{start:startIndex, limit:pagesize}});
},
success: function(form_instance_create, action) {
//Ext.MessageBox.alert('Confirm', action.result.info);
aAddInstanceDlg.hide();
prompt_ds.load({params:{start: startIndex, limit: pagesize}});
}
});
}else{
Ext.MessageBox.alert("<img src='../images/exclamation.gif'> Error!", 'Please fix the errors noted.');
}
});
var layout = aAddInstanceDlg.getLayout();
layout.beginUpdate();
layout.add('center', new Ext.ContentPanel('a-addInstance-inner', {title: 'Add Prompt'}));
layout.endUpdate();
aAddInstanceDlg.show();
};
}
I am not using properly the form.submit's failure part.
failure: function(form_instance_create, action
On server side I have a Struts action servlet with a method as follows:
private boolean addPrompt(HttpServletRequest req) {
System.out
.println("PromptAction::addPrompt()::Enter. promptlist size before add="
+ promptList.size());
System.out.println("PromptAction::addPrompt()::id="
+ req.getParameter(Prompt.PROMPT_ID) + ", text="
+ req.getParameter(Prompt.PROMPT_TEXT) + ", file="
+ req.getParameter(Prompt.PROMPT_FILE));
Prompt p = new Prompt(req.getParameter(Prompt.PROMPT_ID), req
.getParameter(Prompt.PROMPT_TEXT), Prompt.PROMPT_CUSTOM);//@@@, req
//@@@ .getParameter(Prompt.PROMPT_FILE));
promptList.put(req.getParameter(Prompt.PROMPT_ID), p);
// System.out.println("PromptServlet::addPrompt()::Exit. promptlist size
// AFTER add="+ promptList.size());
if (req.getParameter(Prompt.PROMPT_TEXT).length() > 5) {
WDTError promptTextError=new WDTError("wdt.107","Prompt Text too long");
req.setAttribute(WDTConstants.WDT_ERROR, promptTextError);
System.out.println("PromptAction::Error : " + promptTextError.getMessage());
logger.error("PromptAction::Error msg=" + promptTextError.getMessage());
return false;
}
else
return true;
}// End "addPrompt"
Right now no error msg is displayed inside the form.
What all changes are needed on client and server for displaying some sort of Ext.message.alert() message?
Inputs welcome.
The following .js file handles form submit:
function doAdd(){
var startIndex=paging.cursor;
var aAddInstanceDlg;
if (!aAddInstanceDlg) {
aAddInstanceDlg = createNewDialog("a-addInstance-dlg");
aAddInstanceDlg.addButton('Reset', resetForm, aAddInstanceDlg);
aAddInstanceDlg.addButton('Save', function() {
// submit now... all the form information are submit to the server
// handle response after that...
if (form_instance_create.isValid()) {
form_instance_create.submit({ // problem here
// params:{prompt_id : editId, prompt_text: text_edit.getValue(), file: engPrompt_edit.getValue()},
params:{prompt_file: engPrompt_tf.getValue()},
waitMsg:'Adding new prompt now...',
reset: false,
failure: function(form_instance_create, action) {
//TBD: Ext.MessageBox.alert('Error Message', action.result.errorInfo);
//remove following 3 lines
//Ext.MessageBox.alert('Confirm', action.result.info);
var errorMsg='<% = (String)request.getSession().getAttribute("error")%>';
alert('error : '+errorMsg);
Ext.MessageBox.alert('Error Message', action.txt);
//aAddInstanceDlg.hide();
prompt_ds.load({params:{start:startIndex, limit:pagesize}});
},
success: function(form_instance_create, action) {
//Ext.MessageBox.alert('Confirm', action.result.info);
aAddInstanceDlg.hide();
prompt_ds.load({params:{start: startIndex, limit: pagesize}});
}
});
}else{
Ext.MessageBox.alert("<img src='../images/exclamation.gif'> Error!", 'Please fix the errors noted.');
}
});
var layout = aAddInstanceDlg.getLayout();
layout.beginUpdate();
layout.add('center', new Ext.ContentPanel('a-addInstance-inner', {title: 'Add Prompt'}));
layout.endUpdate();
aAddInstanceDlg.show();
};
}
I am not using properly the form.submit's failure part.
failure: function(form_instance_create, action
On server side I have a Struts action servlet with a method as follows:
private boolean addPrompt(HttpServletRequest req) {
System.out
.println("PromptAction::addPrompt()::Enter. promptlist size before add="
+ promptList.size());
System.out.println("PromptAction::addPrompt()::id="
+ req.getParameter(Prompt.PROMPT_ID) + ", text="
+ req.getParameter(Prompt.PROMPT_TEXT) + ", file="
+ req.getParameter(Prompt.PROMPT_FILE));
Prompt p = new Prompt(req.getParameter(Prompt.PROMPT_ID), req
.getParameter(Prompt.PROMPT_TEXT), Prompt.PROMPT_CUSTOM);//@@@, req
//@@@ .getParameter(Prompt.PROMPT_FILE));
promptList.put(req.getParameter(Prompt.PROMPT_ID), p);
// System.out.println("PromptServlet::addPrompt()::Exit. promptlist size
// AFTER add="+ promptList.size());
if (req.getParameter(Prompt.PROMPT_TEXT).length() > 5) {
WDTError promptTextError=new WDTError("wdt.107","Prompt Text too long");
req.setAttribute(WDTConstants.WDT_ERROR, promptTextError);
System.out.println("PromptAction::Error : " + promptTextError.getMessage());
logger.error("PromptAction::Error msg=" + promptTextError.getMessage());
return false;
}
else
return true;
}// End "addPrompt"
Right now no error msg is displayed inside the form.
What all changes are needed on client and server for displaying some sort of Ext.message.alert() message?
Inputs welcome.