Upload file in SmartGWT
来源:互联网 发布:button用js页面跳转 编辑:程序博客网 时间:2024/05/19 16:23
Upload file in SmartGWT
Upload a file to a server from your browser is not a big deal. But how to do it, if you have:- SmartGWT (a Google Web Toolkit with a SmartClient library)
- It is LGPL, so no proprietary extension on a place
- You don't want to use ExtGWT just only for one single upload function and thus risk your project won't really work on older browsers that are still might be in use.
- You want it nicely done at background with a clean callback, of course. :-)
- In com.smartgwt.client.widgets.form.DynamicForm, set it to multipart by passing it Encoding.MULTIPART.
- Create an internal iframe, using com.google.gwt.user.client.ui.NamedFrame and call it, let's say "foo" (sure no better name came into my head now, LOL). Make it 1x1 pixel width and set visibility to false. It is not actually a thing user needs to see.
- Now use setTarget("foo") method to let your DynamicForm use that it as a target.
- Also use setAction(url-to-your-processing-servlet) to let DynamicForm actually send stuff there. You can do it like ("upload" — is your servlet accessible):
.setAction(GWT.getModuleBaseURL() + "/upload"); - Now, add mouse click handler to your IButton and use submitForm() method out of DynamicForm instance object. It will send the form and that iframe we created earlier will receive a result. This way we achieve upload in background.
- Add a native JavaScript method, that will be seen normally in the loaded page, so parent windows can simply call it. That's exactly what do we need, when upload has been finished. More how to add JavaScript native methods, refer to GWT documentation about JSNI.
Your servlet should call back our method, we've defined in step #6. You simply set content type to text/html, write some simple html and a JavaScript that would call parent on window load — this way your iframe will call your client back. You may pass anything you want and respond anything. In my case it just closes upload dialog and says job done.
That's it. Implementation is up to you — use imagination... :-)
sample code
in UI
public UploadPopWindow() {
}
In servlet
0 0
- Upload file in SmartGWT
- File upload example in Jersey
- File upload example in RESTEasy
- upload file
- Upload file
- upload file
- File Upload
- use plupload plugin to upload file in django
- Upload Data from Excel File in ABAP using TEXT_CONVERT_XLS_TO_SAP
- Form-based File Upload in HTML(RFC-1867)
- how to delete .tmp file in server which is created during file upload
- PHP Warning: File upload error - unable to create a temporary file in Unknown on line 0
- File upload by JSP
- simple file upload
- more file upload
- Upload File by SmartUpload
- Upload File Cgi Sample
- upload file into database
- Eclipse的使用快捷键
- 从微软的DBML文件中我们能学到什么(它告诉了我们什么是微软的重中之重)~七 为DBContext对象应该作为其它实体操作类型的基类,并为它提供统一的提交动作
- 面向切面编程(AOP)的理解
- iOS国际化之app内切换语言
- IBM Rational AppScan使用详细说明
- Upload file in SmartGWT
- 临时表空间增长异常
- 第十五章 Delphi开发数据库应用程序概述(七)
- 【Leetcode】二叉树简单路径最大和问题
- MVVM架构~mvc,mvp,mvvm大话开篇
- cocos2d-x常用宏
- 第二十章 简单数据库应用的创建及MASTAPP介绍(九)
- 异或与对称差
- android 群发会话中获取联系人列表