Roughian Examples Site Map - GWT Examples - Tutorials

FileUpload


Version 1.1 onwards

A FileUpload widget allows the user to upload files.



Listeners



Notes


The user can upload files from their file system to a server. This is the only way this can be done.

The FileUpload widget must be inside (and submitted from) a form (FormPanel)


Code


final FormPanel form = new FormPanel();
form.setEncoding(FormPanel.ENCODING_MULTIPART);
form.setMethod(FormPanel.METHOD_POST);
form.addStyleName("table-center");
form.addStyleName("demo-panel-padded");
form.setWidth("275px");

VerticalPanel holder = new VerticalPanel();

FileUpload upload = new FileUpload();
upload.setName("upload");
holder.add(upload);

holder.add(new HTML("<hr />"));

holder.setHorizontalAlignment(HasAlignment.ALIGN_RIGHT);
holder.add(new Button("Submit", new ClickListener()
{
	public void onClick(Widget sender)
	{
		// form.submit();
	}
}));

form.add(holder);

// form.setAction("url");

form.addFormHandler(new FormHandler()
{
	public void onSubmit(FormSubmitEvent event)
	{
		// if (something_is_wrong)
		// {
		// Take some action
		// event.setCancelled(true);
		// }
	}

	public void onSubmitComplete(FormSubmitCompleteEvent event)
	{
		Window.alert(event.getResults());
	}
});

RootPanel.get("demo").add(form);