public class FormPanel extends SimpleContainer implements SubmitEvent.HasSubmitHandlers, SubmitCompleteEvent.HasSubmitCompleteHandlers
SimpleContainer
, which contains only a single
widget. Multiple fields can be added to a form panel by adding them first to
another container and then adding that container to the form panel.
If you do not need to submit a form to a server, consider using one of the
other containers, instead of FormPanel
.
Code snippet for a form panel containing a FileUploadField
:
public void onModuleLoad() { final FormPanel fp = new FormPanel(); FileUploadField fuf = new FileUploadField(); fuf.setName("fileUploadField"); VerticalLayoutContainer vlc = new VerticalLayoutContainer(); vlc.add(new FieldLabel(fuf, "File")); vlc.add(new TextButton("OK", new SelectHandler() { public void onSelect(SelectEvent event) { fp.submit(); } })); fp.setMethod(Method.POST); fp.setEncoding(Encoding.MULTIPART); fp.setAction("http://www.example.com/my_upload_url"); fp.setWidget(vlc); fp.addSubmitCompleteHandler(new SubmitCompleteHandler() { public void onSubmitComplete(SubmitCompleteEvent event) { String resultHtml = event.getResults(); Info.display("Upload Response", resultHtml); } }); Window w = new Window(); w.setHeadingText("Upload File"); w.setPixelSize(300, 100); w.setWidget(fp); w.show(); }
Modifier and Type | Class and Description |
---|---|
static class |
FormPanel.Encoding
Form encoding enumeration.
|
static class |
FormPanel.LabelAlign
Label alignment enumeration.
|
static class |
FormPanel.Method
Form method enumeration.
|
resize, widget
forceLayoutCommand, forceLayoutOnResize, hadLayoutRunning, layoutCommand, layoutRequiredThisEventLoop, layoutRunning
adjustSize, allowTextSelection, cacheSizes, disableContextMenu, disabled, disabledStyle, ensureVisibilityOnSizing, height, hidden, lastSize, layer, left, mask, maskMessage, monitorWindowResize, pageX, pageY, resizeHandler, shim, tabIndex, toolTip, toolTipConfig, top, width, windowResizeDelay, windowResizeTask
Modifier | Constructor and Description |
---|---|
|
FormPanel()
Creates a panel that wraps an HTML form.
|
protected |
FormPanel(Element element,
boolean createIFrame) |
Modifier and Type | Method and Description |
---|---|
HandlerRegistration |
addSubmitCompleteHandler(SubmitCompleteEvent.SubmitCompleteHandler handler)
Adds a
SubmitCompleteEvent handler. |
HandlerRegistration |
addSubmitHandler(SubmitEvent.SubmitHandler handler)
Adds a
SubmitEvent handler. |
String |
getAction()
Gets the 'action' associated with this form.
|
String |
getEncoding()
Gets the encoding used for submitting this form.
|
List<FieldLabel> |
getFieldLabels()
Returns all of the panel's child field labels.
|
List<IsField<?>> |
getFields()
Returns all of the panel's child fields.
|
FormPanel.LabelAlign |
getLabelAlign()
Returns the justification of a field label inside its available space.
|
int |
getLabelWidth()
Returns the width of area available for label text.
|
FormPanel.Method |
getMethod()
Returns the form's method.
|
String |
getTarget()
Gets the form's 'target'.
|
boolean |
isValid()
Returns true if the form is invalid.
|
boolean |
isValid(boolean preventMark)
Returns the form's valid state by querying all child fields.
|
protected void |
onAttach() |
protected void |
onDetach() |
boolean |
onFormSubmit() |
void |
onFrameLoad() |
protected void |
onInsert(int index,
Widget child) |
void |
reset()
Resets all field values.
|
void |
setAction(SafeUri url)
Sets the 'action' associated with this form.
|
void |
setEncoding(FormPanel.Encoding encoding)
Sets the encoding to use when submitting the form.
|
void |
setLabelAlign(FormPanel.LabelAlign align)
Sets the justification of a field label inside its available space.
|
void |
setLabelWidth(int labelWidth)
Sets the width of the padding between the label and the control to which
the label applies.
|
void |
setMethod(FormPanel.Method method)
Specifies if the form will be submitted using an HTTP Post or Get request
(defaults to GET).
|
void |
submit()
Submits the form.
|
add, add, doLayout, getWidget, isResize, onRemove, setElement, setResize, setWidget, setWidget
applyLayout, applyLayout, forceLayout, forceLayoutOnChildren, forceLayoutOnChildren, getLeftRightMargins, getParentLayoutWidget, getSideMargins, getTopBottomMargins, isLayoutRunning, isOrWasLayoutRunning, isWidgetVisible, onBeforeDoLayout, onLoad, onResize, onResize
addAddHandler, addBeforeAddHandler, addBeforeRemoveHandler, addContainerHandler, addRemoveHandler, adjustIndex, adopt, checkIndexBoundsForInsertion, clear, disable, doAttachChildren, doDetachChildren, doPhysicalAttach, doPhysicalDetach, enable, ensureGroupingHandlerRegistration, findWidget, getChildren, getContainerTarget, getItemByItemId, getWidget, getWidgetCount, getWidgetIndex, getWidgetIndex, insert, iterator, onWidgetHide, onWidgetShow, orphan, remove, remove, remove
addBeforeHideHandler, addBeforeShowContextMenuHandler, addBeforeShowHandler, addBlurHandler, addDisableHandler, addEnableHandler, addFocusHandler, addHideHandler, addMoveHandler, addResizeHandler, addShowContextMenuHandler, addShowHandler, addStyleDependentName, addStyleOnOver, adjustPosition, adjustSize, applyState, assertAfterRender, assertPreRender, blur, clearSizeCache, disableContextMenu, disableEvents, enableEvents, fireCancellableEvent, fireEvent, focus, getData, getElement, getFocusEl, getFocusSupport, getHideMode, getId, getItemId, getOffsetHeight, getOffsetWidth, getPositionEl, getShadow, getShadowPosition, getStateId, getTabIndex, getToolTip, hide, hideShadow, hideToolTip, isAllowTextSelection, isAutoHeight, isAutoWidth, isDeferHeight, isEnabled, isMonitorWindowResize, isRendered, isStateful, isVisible, isVisible, mask, mask, notifyHide, notifyShow, onAfterFirstAttach, onBlur, onBrowserEvent, onDisable, onEnable, onFocus, onHide, onHideContextMenu, onPosition, onRightClick, onShow, onShowContextMenu, onUnload, onWindowResize, removeStyleDependentName, removeStyleOnOver, removeToolTip, setAllowTextSelection, setBorders, setBounds, setBounds, setContextMenu, setData, setDeferHeight, setEnabled, setHeight, setHeight, setHideMode, setId, setItemId, setMonitorWindowResize, setPagePosition, setPixelSize, setPosition, setShadow, setShadowPosition, setSize, setStateful, setStateId, setStyleDependentName, setTabIndex, setToolTip, setToolTipConfig, setVisible, setWidth, setWidth, show, sync, syncSize, unmask
public FormPanel()
protected FormPanel(Element element, boolean createIFrame)
public HandlerRegistration addSubmitCompleteHandler(SubmitCompleteEvent.SubmitCompleteHandler handler)
SubmitCompleteEvent
handler.addSubmitCompleteHandler
in interface SubmitCompleteEvent.HasSubmitCompleteHandlers
handler
- the handlerpublic HandlerRegistration addSubmitHandler(SubmitEvent.SubmitHandler handler)
SubmitEvent
handler.addSubmitHandler
in interface SubmitEvent.HasSubmitHandlers
handler
- the handlerpublic String getAction()
public String getEncoding()
FormPanel.Encoding.MULTIPART
or FormPanel.Encoding.URLENCODED
.public List<FieldLabel> getFieldLabels()
public List<IsField<?>> getFields()
public FormPanel.LabelAlign getLabelAlign()
public int getLabelWidth()
public FormPanel.Method getMethod()
public String getTarget()
NamedFrame
that
will receive the results of submission, or null
if none has
been specified.public boolean isValid()
public boolean isValid(boolean preventMark)
preventMark
- true for silent validation (no invalid event and field
is not marked invalid)public boolean onFormSubmit()
public void onFrameLoad()
public void reset()
public void setAction(SafeUri url)
url
- the form's actionpublic void setEncoding(FormPanel.Encoding encoding)
encoding
- the mime encodingpublic void setLabelAlign(FormPanel.LabelAlign align)
align
- the justification of a field label inside its available
spacepublic void setLabelWidth(int labelWidth)
labelWidth
- the width of the padding between the label and the control
to which the label appliespublic void setMethod(FormPanel.Method method)
method
- the methodpublic void submit()
The FormPanel must not be detached (i.e. removed from its parent
or otherwise disconnected from a RootPanel
) until the submission is
complete. Otherwise, notification of submission will fail.
Copyright © 2018. All rights reserved.