Upload File with SmartGWT (LGPL)
Uploading file with SmartGWT is pretty simple - just use the build in DynamicForm component UploadItem. The problem comes in that moment when you need to obtain a notification from server that your upload finished successfully. There is no such an option (out-of-the-box) in LGPL version. There are two ways how to deal with it:
1. Use javascript JSNI call to receive a portion of a code (from server) triggering a function on client side. See this thread http://forums.smartclient.com/forum/smart-gwt-technical-q-a/5624-handling-smartgwt-upload-without-reloading?t=5477
2. Use a raw GWT widgets FormPanel and FileUpload item:
final FormPanel form = new FormPanel(); final FileUpload fu = new FileUpload(); final IButton btnUpload = new IButton("Nahraj"); form.setEncoding(FormPanel.ENCODING_MULTIPART); form.setMethod(FormPanel.METHOD_POST); form.setAction(GWT.getHostPageBaseURL() + "upload"); btnUpload.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { form.submit(); } }); VLayout holder = new VLayout(); fu.setName("upload"); holder.addMember(fu); holder.addMember(btnUpload); form.addSubmitHandler(new FormPanel.SubmitHandler() { public void onSubmit(SubmitEvent event) { btnUpload.setDisabled(true); } }); form.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() { public void onSubmitComplete(SubmitCompleteEvent event) { btnUpload.setDisabled(false); } }); form.add(holder);
Correct - I get the objection that we should't mix GWT and SmartGWT widgets but we can do some exceptions sometimes, right? :-)