Basic File upload in GWT.

131 views
Skip to first unread message

learning coding

unread,
Feb 14, 2012, 5:23:20 AM2/14/12
to Google Web Toolkit, t.br...@gmail.com
Hi all,

I am new to GWT ,
I am writing RPC code to transfer file from client to server.

I have a client side like this.
But i dont understand what i have to call from service class.

i dont know what should i write in interface class and asyncronous
class.

Plz some one Help.
.

public class FileUploader{
private ControlPanel cp;
private FormPanel form = new FormPanel();
private FileUpload fu = new FileUpload();
public FileUploader(ControlPanel cp) {
this.cp = cp;
this.cp.setPrimaryArea(getFileUploaderWidget());
}
@SuppressWarnings("deprecation")
public Widget getFileUploaderWidget() {
form.setEncoding(FormPanel.ENCODING_MULTIPART);
form.setMethod(FormPanel.METHOD_POST);
// form.setAction
(/* WHAT SHOULD I PUT
HERE */);
VerticalPanel holder = new VerticalPanel();
fu.setName("upload");
holder.add(fu);
holder.add(new Button("Submit", new ClickHandler() {
public void onClick(ClickEvent event) {
GWT.log("You selected: " + fu.getFilename(),
null);
form.submit();
}
}));
form.addSubmitHandler(new FormPanel.SubmitHandler() {

public void onSubmit(SubmitEvent event) {
if (!"".equalsIgnoreCase(fu.getFilename())) {
GWT.log("UPLOADING FILE????", null);
// NOW WHAT????
}
else{
event.cancel(); // cancel the event
}
}
});
form.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler()
{
public void onSubmitComplete(SubmitCompleteEvent event) {
Window.alert(event.getResults());
}
});
form.add(holder);
return form;
}
}

Thad

unread,
Feb 14, 2012, 9:18:05 AM2/14/12
to Google Web Toolkit
form.submit(), as in

Button okBtn = new Button("OK");
okBtn.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
form.submit();
}
});

On Feb 14, 5:23 am, learning coding <learning.codin...@gmail.com>
wrote:

learning coding

unread,
Feb 14, 2012, 9:50:14 AM2/14/12
to google-we...@googlegroups.com
form.submit(); is done on Submit buttton.
 
I want to know about the interface, asyncInterface , service ,  and on server  class so that i can read a file on server side.


 
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.


Jens

unread,
Feb 14, 2012, 10:23:09 AM2/14/12
to google-we...@googlegroups.com
You have to create an ordinary HttpServlet, publish it using web.xml and put the published URL into form.setAction(). In your HttpServlet you can then read the uploaded data and save it to database. In your servlet you could use http://commons.apache.org/fileupload/ for reading the data or implement it by hand.

-- J.
Reply all
Reply to author
Forward
0 new messages