I have a problem with gwt-upload: I need onChange Upload to get my object from db; if it exists, the web app can upload file with Servlet, otherwise it will display an alert.
The code with comment runs only in the position with 'It works' comment.
Why doesn't it run in the else block?
final MultiUploader upload = new MultiUploader(FileInputType.BUTTON);
upload.addOnChangeUploadHandler(new OnChangeUploaderHandler() {
@Override
public void onChange(IUploader uploader) {
myService.getMyObject(name, new AsyncCallback<List<Object>>() {
@Override
public void onFailure(Throwable caught) {
Window.alert("Something");
}
@Override
public void onSuccess(List<Object> listMyObject) {
if(listMyObject.size() == 0) {
Window.alert("Error.");
} else {
//It doesn't works.
String url = GWT.getModuleBaseURL() + "upload?nameObject=" + name;
upload.setServletPath(url);
}
}
});
}
});
//It works.
String url = GWT.getModuleBaseURL() + "upload?nameObject=" + name;
upload.setServletPath(url);
You can solve this by adding an upload button and submitting the uploader form on success of the server call. Here's an outline on how to do it. Read gwtupload documentation for adding servlet mapping in web.xml.