eu.webtoolkit.jwt
Class WFormWidget

java.lang.Object
  extended by eu.webtoolkit.jwt.WObject
      extended by eu.webtoolkit.jwt.WWidget
          extended by eu.webtoolkit.jwt.WWebWidget
              extended by eu.webtoolkit.jwt.WInteractWidget
                  extended by eu.webtoolkit.jwt.WFormWidget
Direct Known Subclasses:
WAbstractToggleButton, WComboBox, WLineEdit, WPushButton, WSlider, WTextArea

public abstract class WFormWidget
extends WInteractWidget

An abstract widget that corresponds to an HTML form element.

A WFormWidget may receive focus, can be disabled, and can have a label that acts as proxy for getting focus. It provides signals which reflect changes to its value, or changes to its focus.

Form widgets also have built-in support for validation, using setValidator(). If the validator provide client-side validation, then an invalid validation state is reflected using the style class "Wt-invalid". All validators provided by JWt implement client-side validation.

On the server-side, use validate() method to validate the content using a validator previously set.


Constructor Summary
WFormWidget()
          Creates a WFormWidget with an optional parent.
WFormWidget(WContainerWidget parent)
          Creates a WFormWidget with an optional parent.
 
Method Summary
 EventSignal blurred()
          Signal emitted when the widget lost focus.
 EventSignal changed()
          Signal emitted when the value was changed.
protected  void enableAjax()
          Progresses to an Ajax-enabled widget.
 EventSignal focussed()
          Signal emitted when the widget recieved focus.
 WString getEmptyText()
          Returns the empty text to be shown when the field is empty.
 WLabel getLabel()
          Returns the label associated with this widget.
 int getTabIndex()
          Returns the tab index.
 WValidator getValidator()
          Returns the validator.
abstract  java.lang.String getValueText()
          Returns the current value.
 boolean hasFocus()
          Returns whether this widget has focus.
 boolean isReadOnly()
          Returns whether the form element is read-only.
protected  void propagateSetEnabled(boolean enabled)
          Propagates that a widget was enabled or disabled through children.
 void refresh()
          Refresh the widget.
 void remove()
          Destructor.
protected  void render(java.util.EnumSet<RenderFlag> flags)
           
 EventSignal selected()
          Signal emitted when ??
 void setEmptyText(java.lang.CharSequence emptyText)
          Sets the empty text to be shown when the field is empty.
 void setEnabled(boolean enabled)
          Sets whether the widget is enabled.
 void setFocus()
          Gives focus.
 void setFocus(boolean focus)
          Changes focus.
 void setHidden(boolean hidden, WAnimation animation)
          Sets the hidden state of this widget.
 void setReadOnly(boolean readOnly)
          Sets the element read-only.
 void setTabIndex(int index)
          Sets the tab index.
 void setValidator(WValidator validator)
          Sets a validator for this field.
abstract  void setValueText(java.lang.String value)
          Sets the value text.
 WValidator.State validate()
          Validates the field.
 Signal1<WValidator.Result> validated()
           
 
Methods inherited from class eu.webtoolkit.jwt.WInteractWidget
clicked, doubleClicked, enterPressed, escapePressed, gestureChanged, gestureEnded, gestureStarted, isEnabled, keyPressed, keyWentDown, keyWentUp, load, mouseDragged, mouseMoved, mouseWentDown, mouseWentOut, mouseWentOver, mouseWentUp, mouseWheel, setDraggable, setDraggable, setDraggable, setDraggable, touchEnded, touchMoved, touchStarted
 
Methods inherited from class eu.webtoolkit.jwt.WWebWidget
addStyleClass, callJavaScriptMember, childrenChanged, doJavaScript, domCanBeSaved, escapeText, escapeText, escapeText, escapeText, find, getAttributeValue, getChildren, getClearSides, getDecorationStyle, getFloatSide, getHeight, getId, getJavaScriptMember, getLineHeight, getMargin, getMaximumHeight, getMaximumWidth, getMinimumHeight, getMinimumWidth, getOffset, getPositionScheme, getStyleClass, getToolTip, getVerticalAlignment, getVerticalAlignmentLength, getWidth, isDisabled, isHidden, isHiddenKeepsGeometry, isInline, isLoaded, isPopup, isRendered, isVisible, jsStringLiteral, jsStringLiteral, removeScript, removeStyleClass, resize, setAttributeValue, setClearSides, setDecorationStyle, setDisabled, setFloatSide, setHiddenKeepsGeometry, setId, setInline, setJavaScriptMember, setLineHeight, setLoadLaterWhenInvisible, setMargin, setMaximumSize, setMinimumSize, setOffsets, setPopup, setPositionScheme, setSelectable, setStyleClass, setToolTip, setVerticalAlignment, updateSignalConnection
 
Methods inherited from class eu.webtoolkit.jwt.WWidget
acceptDrops, acceptDrops, addCssRule, addCssRule, addStyleClass, animateHide, animateShow, boxBorder, boxPadding, containsExposed, disable, dropEvent, enable, getDrop, getJsRef, getParent, hide, htmlText, isLayoutSizeAware, layoutSizeChanged, positionAt, positionAt, removeStyleClass, resize, setClearSides, setHeight, setHidden, setLayoutSizeAware, setMargin, setMargin, setMargin, setMargin, setMargin, setOffsets, setOffsets, setOffsets, setOffsets, setOffsets, setToolTip, setVerticalAlignment, setWidth, show, stopAcceptDrops, toggleStyleClass, toggleStyleClass, tr
 
Methods inherited from class eu.webtoolkit.jwt.WObject
addChild, getObjectName, setObjectName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WFormWidget

public WFormWidget(WContainerWidget parent)
Creates a WFormWidget with an optional parent.


WFormWidget

public WFormWidget()
Creates a WFormWidget with an optional parent.

Calls this((WContainerWidget)null)

Method Detail

remove

public void remove()
Destructor.

If a label was associated with the widget, its buddy is reset to null.

Overrides:
remove in class WInteractWidget
See Also:
WContainerWidget.removeWidget(WWidget widget)

getLabel

public WLabel getLabel()
Returns the label associated with this widget.

Returns the label (if there is one) that acts as a proxy for this widget.

See Also:
WLabel.setBuddy(WFormWidget buddy)

setHidden

public void setHidden(boolean hidden,
                      WAnimation animation)
Sets the hidden state of this widget.

If the widget has a label, it is hidden and shown together with this widget.

Overrides:
setHidden in class WWebWidget

getValueText

public abstract java.lang.String getValueText()
Returns the current value.

This returns the current value as a string.


setValueText

public abstract void setValueText(java.lang.String value)
Sets the value text.

This sets the current value from a string value.


setValidator

public void setValidator(WValidator validator)
Sets a validator for this field.

The validator is used to validate the current input.

If the validator has no parent yet, then ownership is transferred to the form field, and thus the validator will be deleted together with the form field.

The default value is null.

See Also:
validate()

getValidator

public WValidator getValidator()
Returns the validator.


validate

public WValidator.State validate()
Validates the field.


setEnabled

public void setEnabled(boolean enabled)
Sets whether the widget is enabled.

A widget that is disabled cannot receive focus or user interaction.

This is the opposite of WWebWidget#setDisabled().


setFocus

public void setFocus()
Gives focus.

Giving focus to an input element only works when JavaScript is enabled.


setFocus

public void setFocus(boolean focus)
Changes focus.

When using focus = false, you can undo a previous setFocus() call.


hasFocus

public boolean hasFocus()
Returns whether this widget has focus.


setTabIndex

public void setTabIndex(int index)
Description copied from class: WWidget
Sets the tab index.

For widgets that receive focus, focus is passed on to the next widget in the tabbing chain based on their tab index. When the user navigates through form widgets using the keyboard, widgets receive focus starting from the element with the lowest tab index to elements with the highest tab index.

A tab index only applies to widgets than can receive focus (which are WFormWidget, WAnchor, WPushButton), but setting a tab index on any other type of widget will propagate to its contained form widgets.

Widgets with a same tab index will receive focus in the same order as they are inserted in the widget tree.

The default tab index is 0.

Overrides:
setTabIndex in class WWebWidget

getTabIndex

public int getTabIndex()
Description copied from class: WWidget
Returns the tab index.

Overrides:
getTabIndex in class WWebWidget
See Also:
WWidget.setTabIndex(int index)

setReadOnly

public void setReadOnly(boolean readOnly)
Sets the element read-only.

A read-only form element cannot be edited, but the contents can still be selected.

By default, a form element area is not read-only.

See Also:
setEnabled(boolean enabled)

isReadOnly

public boolean isReadOnly()
Returns whether the form element is read-only.

See Also:
setReadOnly(boolean readOnly)

setEmptyText

public void setEmptyText(java.lang.CharSequence emptyText)
Sets the empty text to be shown when the field is empty.

See Also:
getEmptyText()

getEmptyText

public WString getEmptyText()
Returns the empty text to be shown when the field is empty.

See Also:
setEmptyText(CharSequence emptyText)

changed

public EventSignal changed()
Signal emitted when the value was changed.


selected

public EventSignal selected()
Signal emitted when ??


blurred

public EventSignal blurred()
Signal emitted when the widget lost focus.


focussed

public EventSignal focussed()
Signal emitted when the widget recieved focus.


validated

public Signal1<WValidator.Result> validated()

refresh

public void refresh()
Description copied from class: WWidget
Refresh the widget.

The refresh method is invoked when the locale is changed using WApplication#setLocale() or when the user hit the refresh button.

The widget must actualize its contents in response.

Overrides:
refresh in class WWebWidget

enableAjax

protected void enableAjax()
Description copied from class: WWidget
Progresses to an Ajax-enabled widget.

This method is called when the progressive bootstrap method is used, and support for AJAX has been detected. The default behavior will upgrade the widget's event handling to use AJAX instead of full page reloads, and propagate the call to its children.

You may want to reimplement this method if you want to make changes to widget when AJAX is enabled. You should always call the base implementation.

Overrides:
enableAjax in class WWebWidget
See Also:
WApplication.enableAjax()

render

protected void render(java.util.EnumSet<RenderFlag> flags)
Overrides:
render in class WWebWidget

propagateSetEnabled

protected void propagateSetEnabled(boolean enabled)
Description copied from class: WWidget
Propagates that a widget was enabled or disabled through children.

When enabling or disabling a widget, you usually also want to disable contained children. This method is called by setDisabled() to propagate its state to all children.

You may want to reimplement this method if they wish to render differently when a widget is disabled. The default implementation will propagate the signal to all children.

Overrides:
propagateSetEnabled in class WInteractWidget