Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.google.gwt.user.client.ui
Class FileUpload

    java.lang.Object
      com.google.gwt.user.client.ui.UIObject
          com.google.gwt.user.client.ui.Widget
              com.google.gwt.user.client.ui.FileUpload

All Implemented Interfaces:
  EventListener, HasName

    public class FileUpload

extends Widget
implements HasName

A widget that wraps the HTML <input type='file'> element. This widget must be used with `FormPanel` if it is to be submitted to a server.

### Example

>     public class FormPanelExample implements EntryPoint {

>       public void onModuleLoad() {
>         // Create a FormPanel and point it at a service.
>         final FormPanel form = new FormPanel();
>         form.setAction("/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);

>         // Create a panel to hold all of the form widgets.
>         VerticalPanel panel = new VerticalPanel();
>         form.setWidget(panel);

>         // Create a TextBox, giving it a name so that it will be submitted.
>         final TextBox tb = new TextBox();
>         tb.setName("textBoxFormElement");
>         panel.add(tb);

>         // Create a ListBox, giving it a name and some values to be associated with
>         // its options.
>         ListBox lb = new ListBox();
>         lb.setName("listBoxFormElement");
>         lb.addItem("foo", "fooValue");
>         lb.addItem("bar", "barValue");
>         lb.addItem("baz", "bazValue");
>         panel.add(lb);

>         // Create a FileUpload widget.
>         FileUpload upload = new FileUpload();
>         upload.setName("uploadFormElement");
>         panel.add(upload);

>         // Add a 'submit' button.
>         panel.add(new Button("Submit", new ClickListener() {
>           public void onClick(Widget sender) {
>             form.submit();
>           }
>         }));

>         // Add an event handler to the form.
>         form.addFormHandler(new FormHandler() {
>           public void onSubmit(FormSubmitEvent event) {
>             // This event is fired just before the form is submitted. We can take
>             // this opportunity to perform validation.
>             if (tb.getText().length() == 0) {
>               Window.alert("The text box must not be empty");
>               event.setCancelled(true);
>             }
>           }

>           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());
>           }
>         });

>         RootPanel.get().add(form);
>       }
>     }

Constructor Summary
`FileUpload()` Constructs a new file upload widget.

Method Summary
`java.lang.String` | `getFilename()` Gets the filename selected by the user.
`java.lang.String` | `getName()` Gets the widget's name.
`void` | `setName(java.lang.String name)` Sets the widget's name.

Methods inherited from class com.google.gwt.user.client.ui.Widget
`doAttachChildren, doDetachChildren, getParent, isAttached, onAttach, onBrowserEvent, onDetach, onLoad, onUnload, removeFromParent, setElement`

Methods inherited from class com.google.gwt.user.client.ui.UIObject
`addStyleDependentName, addStyleName, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, removeStyleDependentName, removeStyleName, setHeight, setPixelSize, setSize, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkEvents, toString, unsinkEvents`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### FileUpload

    public FileUpload()

  Constructs a new file upload widget.

Method Detail

### getFilename

    public java.lang.String getFilename()

  Gets the filename selected by the user. This property has no mutator, as browser security restrictions preclude setting it.

  Returns:
    the widget's filename

### getName

    public java.lang.String getName()

  Description copied from interface: `HasName`
  Gets the widget's name.

  Specified by:
    `getName` in interface `HasName`
  Returns:
    the widget's name

### setName

    public void setName(java.lang.String name)

  Description copied from interface: `HasName`
  Sets the widget's name.

  Specified by:
    `setName` in interface `HasName`
  Parameters:
    `name` - the widget's new name

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD