01: /*
02: * Copyright 2006 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.user.client.ui;
17:
18: import com.google.gwt.user.client.DOM;
19:
20: /**
21: * A widget that wraps the HTML <input type='file'> element. This widget
22: * must be used with {@link com.google.gwt.user.client.ui.FormPanel} if it is
23: * to be submitted to a server.
24: *
25: * <p>
26: * <h3>Example</h3> {@example com.google.gwt.examples.FormPanelExample}
27: * </p>
28: */
29: public class FileUpload extends Widget implements HasName {
30:
31: /**
32: * Constructs a new file upload widget.
33: */
34: public FileUpload() {
35: setElement(DOM.createElement("input"));
36: DOM.setElementProperty(getElement(), "type", "file");
37: setStyleName("gwt-FileUpload");
38: }
39:
40: /**
41: * Gets the filename selected by the user. This property has no mutator, as
42: * browser security restrictions preclude setting it.
43: *
44: * @return the widget's filename
45: */
46: public String getFilename() {
47: return DOM.getElementProperty(getElement(), "value");
48: }
49:
50: public String getName() {
51: return DOM.getElementProperty(getElement(), "name");
52: }
53:
54: public void setName(String name) {
55: DOM.setElementProperty(getElement(), "name", name);
56: }
57: }
|