raimon@extjs
14 May 2009, 1:36 AM
Hi, i am using FormPanel together with FileUploadField for uploading a file to a regular servlet (not a gwt service). this all works correctly, that is, the file is selected and uploaded to the servlet. what is missing however is the option of evaluating the response from the servlet. Formpanel does not get an Events.Submit event so it is impossible a) to detect when the request has completed and b) to give some kind of feedback on the cleint when smthg goes wrong. On the other side, enabling a listener for Events.BeforeSubmit works fine. The new gwt 1.6 has a file upload mechanism with callback functions in error case and normal response. i was wondering if u are using this options at all. here is some code on what im doeing
protected void onRender(Element parent, int index) {
super.onRender(parent, index);
setStyleAttribute("margin", "10px");
final FormPanel panel = new FormPanel();
panel.setHeaderVisible(false);
panel.setFrame(false);
panel.setBorders(false);
panel.setAutoWidth(true);
panel.setAction(GWT.getModuleBaseURL() + "profileupload");
panel.setEncoding(Encoding.MULTIPART);
panel.setMethod(Method.POST);
panel.setButtonAlign(HorizontalAlignment.LEFT);
panel.setWidth(350);
// THIS DOES NOT WORK ie handler is not called on completion
panel.addListener(Events.Submit, new Listener<FormEvent>() {
@Override
public void handleEvent(FormEvent be) {
log("UploadEvent " + be.getEvent() + " " + be.getResultHtml());
}
});
// THIS WORKS
panel.addListener(Events.BeforeSubmit, new Listener<FormEvent>(){
@Override
public void handleEvent(FormEvent be) {
log("beforeSubmit event");
}
});
TextField<String> profilename = new TextField<String>();
profilename.setAllowBlank(false);
profilename.setName("profilename");
profilename.setFieldLabel("Profilname");
panel.add(profilename);
FileUploadField uploadfile = new FileUploadField();
uploadfile.setAllowBlank(false);
uploadfile.setFieldLabel("File");
uploadfile.setName("profile");
uploadfile.setAutoWidth(true);
panel.add(uploadfile);
Button uploadbtn = new Button("Uploaden", new SelectionListener<ButtonEvent>() {
public void componentSelected(ButtonEvent ce) {
if (!panel.isValid()) {
return;
}
panel.submit();
}
});
panel.addButton(uploadbtn);
add(panel);
}
the servlet is just a plain servlet which return some data using the response request as "text/html"
raimon
protected void onRender(Element parent, int index) {
super.onRender(parent, index);
setStyleAttribute("margin", "10px");
final FormPanel panel = new FormPanel();
panel.setHeaderVisible(false);
panel.setFrame(false);
panel.setBorders(false);
panel.setAutoWidth(true);
panel.setAction(GWT.getModuleBaseURL() + "profileupload");
panel.setEncoding(Encoding.MULTIPART);
panel.setMethod(Method.POST);
panel.setButtonAlign(HorizontalAlignment.LEFT);
panel.setWidth(350);
// THIS DOES NOT WORK ie handler is not called on completion
panel.addListener(Events.Submit, new Listener<FormEvent>() {
@Override
public void handleEvent(FormEvent be) {
log("UploadEvent " + be.getEvent() + " " + be.getResultHtml());
}
});
// THIS WORKS
panel.addListener(Events.BeforeSubmit, new Listener<FormEvent>(){
@Override
public void handleEvent(FormEvent be) {
log("beforeSubmit event");
}
});
TextField<String> profilename = new TextField<String>();
profilename.setAllowBlank(false);
profilename.setName("profilename");
profilename.setFieldLabel("Profilname");
panel.add(profilename);
FileUploadField uploadfile = new FileUploadField();
uploadfile.setAllowBlank(false);
uploadfile.setFieldLabel("File");
uploadfile.setName("profile");
uploadfile.setAutoWidth(true);
panel.add(uploadfile);
Button uploadbtn = new Button("Uploaden", new SelectionListener<ButtonEvent>() {
public void componentSelected(ButtonEvent ce) {
if (!panel.isValid()) {
return;
}
panel.submit();
}
});
panel.addButton(uploadbtn);
add(panel);
}
the servlet is just a plain servlet which return some data using the response request as "text/html"
raimon