Hi,
for a simple file upload i'm using an UploadItem with a "native submit".
The file upload is working in general, but in case of a failure the handler added with addFormSubmitFailedHandler() is not invoked.
Complete example code:
Tested:
* the file is removed after choosing it in upload item but before hitting the upload button
* the submit URL is wrong / server is not reachable
* server responds with HTTP error code
In all cases the FormSubmitFailedHandler is not called.
The result frame set here with setTarget() is a hidden frame in the index.html. ( iframe height="0" name="upload_frame"></iframe> )
If it is not set, the page is reloading and it is unclear if the handler was invoked.
I'm not sure if the FormSubmitFailedHandler can even be used here in this case (with or without target frame). The documentation is unclear about this.
v12.0p_2018-07-12/LGPL Development Only (built 2018-07-12)
Chrome 70
for a simple file upload i'm using an UploadItem with a "native submit".
The file upload is working in general, but in case of a failure the handler added with addFormSubmitFailedHandler() is not invoked.
Complete example code:
Code:
public class TestEntryPoint implements EntryPoint { private static final Logger logger = Logger.getLogger(TestEntryPoint.class.getName()); @Override public void onModuleLoad() { DynamicForm dynamicForm = new DynamicForm(); dynamicForm.setAutoFocus(true); final DynamicForm uploadForm = new DynamicForm(); uploadForm.setEncoding(Encoding.MULTIPART); uploadForm.setMethod(FormMethod.POST); // set hidden upload frame as target. Prevents reloading page. uploadForm.setTarget("upload_frame"); uploadForm.setCanSubmit(true); // event never fired uploadForm.addFormSubmitFailedHandler(event -> logger.warning("Upload failed")); UploadItem fileItem = new UploadItem(); fileItem.setShowTitle(false); fileItem.setMultiple(false); IButton uploadButton = new IButton("Upload!"); uploadButton.addClickHandler(e -> startFileUpload(uploadForm)); uploadForm.setItems(fileItem); Layout layout = new VLayout(); layout.setAutoHeight(); layout.setMembers(uploadForm, uploadButton); CanvasItem canvasItem = new CanvasItem(); canvasItem.setCanvas(layout); dynamicForm.setItems(canvasItem); dynamicForm.draw(); } private void startFileUpload(DynamicForm uploadForm) { logger.info("Start file upload"); uploadForm.setAction("http://localhost:8080/upload_endpoint"); uploadForm.submitForm(); } }
* the file is removed after choosing it in upload item but before hitting the upload button
* the submit URL is wrong / server is not reachable
* server responds with HTTP error code
In all cases the FormSubmitFailedHandler is not called.
The result frame set here with setTarget() is a hidden frame in the index.html. ( iframe height="0" name="upload_frame"></iframe> )
If it is not set, the page is reloading and it is unclear if the handler was invoked.
I'm not sure if the FormSubmitFailedHandler can even be used here in this case (with or without target frame). The documentation is unclear about this.
v12.0p_2018-07-12/LGPL Development Only (built 2018-07-12)
Chrome 70
Comment