|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.gwt.user.client.ui.UIObject
com.google.gwt.user.client.ui.Widget
com.google.gwt.user.client.ui.Panel
com.google.gwt.user.client.ui.SimplePanel
com.google.gwt.user.client.ui.FormPanel
public class FormPanel
A panel that wraps its contents in an HTML <FORM> element.
This panel can be used to achieve interoperability with servers that accept
traditional HTML form encoding. The following widgets (those that implement
HasName
) will be submitted to the
server if they are contained within this panel:
FileUpload
is only
useful when used within a FormPanel, because the browser will only upload
files using form submission.
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 onSubmitComplete(FormSubmitCompleteEvent event) { // When the form submission is successfully completed, this event is // fired. Assuming the service returned a response of type text/plain, // we can get the result text here (see the FormPanel documentation for // further explanation). Window.alert(event.getResults()); } 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); } } }); RootPanel.get().add(form); } }
Field Summary | |
---|---|
static java.lang.String |
ENCODING_MULTIPART
Used with setEncoding(String) to specify that the form will be
submitted using MIME encoding (necessary for FileUpload to work
properly). |
static java.lang.String |
ENCODING_URLENCODED
Used with setEncoding(String) to specify that the form will be
submitted using traditional URL encoding. |
static java.lang.String |
METHOD_GET
Used with setMethod(String) to specify that the form will be
submitted using an HTTP GET request. |
static java.lang.String |
METHOD_POST
Used with setMethod(String) to specify that the form will be
submitted using an HTTP POST request (necessary for FileUpload to
work properly). |
Constructor Summary | |
---|---|
FormPanel()
Creates a new FormPanel. |
|
FormPanel(NamedFrame frameTarget)
Creates a FormPanel that targets a NamedFrame . |
|
FormPanel(java.lang.String target)
Creates a new FormPanel. |
Method Summary | |
---|---|
void |
addFormHandler(FormHandler handler)
Adds a handler interface to receive click events. |
java.lang.String |
getAction()
Gets the 'action' associated with this form. |
java.lang.String |
getEncoding()
Gets the encoding used for submitting this form. |
java.lang.String |
getMethod()
Gets the HTTP method used for submitting this form. |
java.lang.String |
getTarget()
Gets the form's 'target'. |
protected void |
onAttach()
This method is called when a widget is attached to the browser's document. |
protected void |
onDetach()
This method is called when a widget is detached from the browser's document. |
boolean |
onFormSubmit()
|
void |
onFrameLoad()
|
void |
removeFormHandler(FormHandler handler)
Removes a previously added handler interface. |
void |
setAction(java.lang.String url)
Sets the 'action' associated with this form. |
void |
setEncoding(java.lang.String encodingType)
Sets the encoding used for submitting this form. |
void |
setMethod(java.lang.String method)
Sets the HTTP method used for submitting this form. |
void |
submit()
Submits the form. |
Methods inherited from class com.google.gwt.user.client.ui.SimplePanel |
---|
add, getContainerElement, getWidget, iterator, remove, setWidget |
Methods inherited from class com.google.gwt.user.client.ui.Panel |
---|
adopt, clear, disown |
Methods inherited from class com.google.gwt.user.client.ui.Widget |
---|
getParent, isAttached, onBrowserEvent, onLoad, removeFromParent |
Methods inherited from class com.google.gwt.user.client.ui.UIObject |
---|
addStyleName, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleName, getTitle, isVisible, isVisible, removeStyleName, setElement, setHeight, setPixelSize, setSize, setStyleName, setStyleName, setTitle, setVisible, setVisible, setWidth, sinkEvents, toString, unsinkEvents |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String ENCODING_MULTIPART
setEncoding(String)
to specify that the form will be
submitted using MIME encoding (necessary for FileUpload
to work
properly).
public static final java.lang.String ENCODING_URLENCODED
setEncoding(String)
to specify that the form will be
submitted using traditional URL encoding.
public static final java.lang.String METHOD_GET
setMethod(String)
to specify that the form will be
submitted using an HTTP GET request.
public static final java.lang.String METHOD_POST
setMethod(String)
to specify that the form will be
submitted using an HTTP POST request (necessary for FileUpload
to
work properly).
Constructor Detail |
---|
public FormPanel()
FormHandler
.
The back-end server is expected to respond with a content-type of 'text/plain'. If any other content-type is specified by the server, then the result text sent in the onFormSubmit event will be unpredictable across browsers.
public FormPanel(NamedFrame frameTarget)
NamedFrame
. The target frame is
not physically attached to the form, and must therefore still be added to a
panel elsewhere.
When the FormPanel targets an external frame in this way, it will not fire the onFormSubmit event.
frameTarget
- the NamedFrame
to be targettedpublic FormPanel(java.lang.String target)
When the FormPanel targets an external frame in this way, it will not fire the onFormSubmit event.
target
- the name of the <iframe> to receive the results of the
submission, or null
to specify that the current
page be replacedMethod Detail |
---|
public void addFormHandler(FormHandler handler)
FiresFormEvents
addFormHandler
in interface FiresFormEvents
handler
- the handler interface to addpublic java.lang.String getAction()
public java.lang.String getEncoding()
ENCODING_MULTIPART
or ENCODING_URLENCODED
.
public java.lang.String getMethod()
METHOD_GET
or METHOD_POST
.
public java.lang.String getTarget()
NamedFrame
that
will receive the results of submission, or null
if none has
been specified.
public boolean onFormSubmit()
onFormSubmit
in interface com.google.gwt.user.client.ui.impl.FormPanelImplHost
public void onFrameLoad()
onFrameLoad
in interface com.google.gwt.user.client.ui.impl.FormPanelImplHost
public void removeFormHandler(FormHandler handler)
FiresFormEvents
removeFormHandler
in interface FiresFormEvents
handler
- the handler interface to removepublic void setAction(java.lang.String url)
url
- the form's actionpublic void setEncoding(java.lang.String encodingType)
ENCODING_MULTIPART
or ENCODING_URLENCODED
.
encodingType
- the form's encodingpublic void setMethod(java.lang.String method)
METHOD_GET
or METHOD_POST
.
method
- the form's methodpublic void submit()
protected void onAttach()
Widget
Panel
. To receive
notification when a widget is attached to the document, override the
Widget.onLoad()
method.
onAttach
in class Panel
protected void onDetach()
Widget
Panel
.
onDetach
in class Panel
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |