it doesn't works...

any hints?
Here's how I did it, for those interested.
Please drop me a comment if you know of a better way, or at least a way to improve what I've already done.
On the client side, as gslender suggests, I had to get the FileUpload widget working outside of GXT first (to make sure everything was working). You must use the FormPanel (http://google-web-toolkit.googlecode...w-summary.html) widget with the FileUpload widget... since the FileUpload widget just wraps <input type="file"> it must be used within the <form></form> tags (which is what FormPanel wraps). Unfortunately, I found no way of doing file uploads with RPC :-(
I used the following code
Client:
Code:
public void onModuleLoad() {
final FormPanel form = new FormPanel();
form.setAction(GWT.getModuleBaseURL() + "/myFormHandler");
// Because we're going to add a FileUpload widget, we'll need to set the
// form to use the POST method, and multipart MIME encoding.
form.setEncoding(FormPanel.ENCODING_MULTIPART);
form.setMethod(FormPanel.METHOD_POST);
VerticalPanel panel = new VerticalPanel();
form.setWidget(panel);
// Create a FileUpload widget.
FileUpload upload = new FileUpload();
upload.setName("uploadFormElement");
panel.add(upload);
Button button2 = new Button("Submit", new ClickListener() {
public void onClick(Widget sender) {
form.submit();
}
});
// Add a 'submit' button.
panel.add(button2);
// Add an event handler to the form.
form.addFormHandler(new FormHandler() {
public void onSubmitComplete(FormSubmitCompleteEvent event) {
// When the form submission is successfully completed, this
// event is
// fired. Assuming the service returned a response of type
// text/html,
// we can get the result text here (see the FormPanel
// documentation for
// further explanation).
Window.alert(event.getResults());
}
public void onSubmit(FormSubmitEvent event) {
// TODO Auto-generated method stub
}
});
RootPanel.get().add(form);
}
<module>.gwt.xml
add this line:
Code:
<servlet path="/myFormHandler" class="com.posta.samples.server.MyFormHandler"/>
Server (using Commons-FileUpload and Commons-IO... with much guidance from this website: http://balusc.blogspot.com/2007/07/fileservlet.html):
Code:
public class MyFormHandler extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("text/html");
FileItem uploadItem = getFileItem(req);
if(uploadItem == null) {
resp.getWriter().write("NO-SCRIPT-DATA");
return;
}
resp.getWriter().write(new String(uploadItem.get()));
}
private FileItem getFileItem(HttpServletRequest req) {
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
try {
List items = upload.parseRequest(req);
Iterator it = items.iterator();
while(it.hasNext()) {
FileItem item = (FileItem) it.next();
if(!item.isFormField() && "uploadFormElement".equals(item.getFieldName())) {
return item;
}
}
}
catch(FileUploadException e){
return null;
}
return null;
}
}
I have also implemented file download and file delete. Let me know whether there is interest in that.