Class WTemplateFormView
- Direct Known Subclasses:
AuthWidget
,RegistrationWidget
,UpdatePasswordWidget
This implements a View to be used in conjunction with WFormModel
models to implement
forms.
For each model field, it uses a number of conventional template placeholder variables to represent the label, editor, and validation messages in the template. For a field name 'field', we have:
- 'field': the actual (form) widget for viewing/editing the value
- 'field-label': the label text
- 'field-info': a text that contains help or validation messages
- 'if:field': condition for the visibility of the field
A typical template uses blocks of the following-format (in the example below illustrated for a field 'UserName'):
${<if:UserName>}
<label for="${id:UserName}">${UserName-label}</label>
${UserName} ${UserName-info}
${</if:UserName>}
The View may render fields of more than one model, and does not necessarily need to render all
information of each model. The latter can be achieved by either calling updateViewField()
and updateModelField()
for
individual model fields, or by hiding fields in the model that are not to be shown in the view.
The updateView()
method updates the
view based on a model (e.g. to propagate changed values or validation feed-back), while the
updateModel()
method updates the model
with values entered in the View.
The view is passive: it will not perform any updates by itself of either the View or Model.
You will typically bind a method to the StandardButton.Ok
button and do:
void okClicked()
{
updateModel(this.model);
if (this.model.validate()) {
...
} else {
updateView(this.model);
}
}
-
Nested Class Summary
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WTemplate
WTemplate.Function, WTemplate.Functions
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData
-
Field Summary
Fields inherited from class eu.webtoolkit.jwt.WInteractWidget
dragTouchEndSlot_, dragTouchSlot_
-
Constructor Summary
ConstructorDescriptionConstructor.WTemplateFormView
(WContainerWidget parentContainer) Constructor.Constructor.WTemplateFormView
(CharSequence text, WContainerWidget parentContainer) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected WWidget
createFormWidget
(String field) Creates a form widget.protected void
indicateValidation
(String field, boolean validated, WText info, WWidget edit, WValidator.Result validation) Indicates the validation result.void
setFormWidget
(String field, WWidget formWidget) Sets the form widget for a given field.void
setFormWidget
(String field, WWidget formWidget, Runnable updateViewValue, Runnable updateModelValue) Sets the form widget for a given field.void
updateModel
(WFormModel model) Updates the Model.void
updateModelField
(WFormModel model, String field) Updates a field in the Model.void
updateModelValue
(WFormModel model, String field, WFormWidget edit) Updates a value in the Model.boolean
updateModelValue
(WFormModel model, String field, WWidget edit) Updates a value in the Model.void
updateView
(WFormModel model) Updates the View.void
updateViewField
(WFormModel model, String field) Creates or updates a field in the View.void
updateViewValue
(WFormModel model, String field, WFormWidget edit) Updates the value in the View.boolean
updateViewValue
(WFormModel model, String field, WWidget edit) Updates the value in the View.Methods inherited from class eu.webtoolkit.jwt.WTemplate
addFunction, applyArguments, bindEmpty, bindInt, bindString, bindString, bindWidget, clear, conditionValue, enableAjax, format, format, format, format, getConditionsSet, getErrorText, getTemplateText, getWidgetIdMode, getWidgets, handleUnresolvedVariable, hasInternalPathEncoding, isEncodeTemplateText, iterateChildren, refresh, remove, removeWidget, removeWidget, renderTemplate, renderTemplateText, reset, resolveFunction, resolveString, resolveStringValue, resolveWidget, setCondition, setEncodeTemplateText, setInternalPathEncoding, setTemplateText, setTemplateText, setWidgetIdMode, varName
Methods inherited from class eu.webtoolkit.jwt.WInteractWidget
clicked, doubleClicked, enterPressed, escapePressed, gestureChanged, gestureEnded, gestureStarted, getMouseOverDelay, isEnabled, keyPressed, keyWentDown, keyWentUp, load, mouseDragged, mouseMoved, mouseWentDown, mouseWentOut, mouseWentOver, mouseWentUp, mouseWheel, propagateSetEnabled, setDraggable, setDraggable, setDraggable, setDraggable, setMouseOverDelay, setPopup, touchEnded, touchMoved, touchStarted, unsetDraggable
Methods inherited from class eu.webtoolkit.jwt.WWebWidget
addStyleClass, beingDeleted, blurred, callJavaScriptMember, childrenChanged, createDomElement, doJavaScript, escapeText, escapeText, escapeText, escapeText, find, findById, focussed, getAttributeValue, getBaseZIndex, getChildren, getClearSides, getDecorationStyle, getDomChanges, getFloatSide, getHeight, getHtmlTagName, getId, getJavaScriptMember, getLineHeight, getMargin, getMaximumHeight, getMaximumWidth, getMinimumHeight, getMinimumWidth, getOffset, getPositionScheme, getScrollVisibilityMargin, getStyleClass, getTabIndex, getToolTip, getVerticalAlignment, getVerticalAlignmentLength, getWidth, hasFocus, hasStyleClass, isCanReceiveFocus, isDisabled, isHidden, isHiddenKeepsGeometry, isInline, isLoaded, isPopup, isRendered, isScrollVisibilityEnabled, isScrollVisible, isSetFirstFocus, isThemeStyleEnabled, isVisible, jsStringLiteral, jsStringLiteral, manageWidget, parentResized, parentResized, propagateSetVisible, removeScript, removeStyleClass, render, resize, scrollVisibilityChanged, setAttributeValue, setBaseZIndex, setCanReceiveFocus, setClearSides, setDecorationStyle, setDeferredToolTip, setDisabled, setFlexBox, setFloatSide, setFocus, setHidden, setHiddenKeepsGeometry, setHtmlTagName, setId, setInline, setJavaScriptMember, setLineHeight, setLoadLaterWhenInvisible, setMargin, setMaximumSize, setMinimumSize, setObjectName, setOffsets, setParentWidget, setPositionScheme, setScrollVisibilityEnabled, setScrollVisibilityMargin, setSelectable, setStyleClass, setTabIndex, setThemeStyleEnabled, setToolTip, setVerticalAlignment, unescapeText, updateSignalConnection, voidEventSignal, widgetAdded, widgetRemoved
Methods inherited from class eu.webtoolkit.jwt.WWidget
acceptDrops, acceptDrops, addCssRule, addCssRule, addJSignal, addStyleClass, animateHide, animateShow, boxBorder, boxPadding, createJavaScript, disable, dropEvent, enable, getDropTouch, getJsRef, getParent, hide, htmlText, isExposed, isGlobalWidget, isLayoutSizeAware, layoutSizeChanged, needsRerender, positionAt, positionAt, removeFromParent, removeStyleClass, render, resize, scheduleRender, scheduleRender, scheduleRender, setClearSides, setDeferredToolTip, setFocus, 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
getObjectName, setFormData
-
Constructor Details
-
WTemplateFormView
Constructor.For convenience, this initializes the template with:
addFunction("id", Functions.id); addFunction("tr", Functions.tr); addFunction("block", Functions.block);
-
WTemplateFormView
public WTemplateFormView()Constructor. -
WTemplateFormView
Constructor.For convenience, this initializes the template with:
addFunction("id", Functions.id); addFunction("tr", Functions.tr); addFunction("block", Functions.block);
-
WTemplateFormView
Constructor.
-
-
Method Details
-
setFormWidget
Sets the form widget for a given field.When the
widget
is a form widget, then the View class will useWFormWidget#setValueText()
to update it with model values, andWFormWidget.getValueText()
to update the model with view data.You can override this default behaviour by either using the overloaded
setFormWidget()
that allows to specify these functions, or reimplementupdateViewValue()
orupdateModelValue()
. -
setFormWidget
public void setFormWidget(String field, WWidget formWidget, Runnable updateViewValue, Runnable updateModelValue) Sets the form widget for a given field.This overloaded functions allows functions to be provided to update the view and model for this field.
-
updateView
Updates the View.This creates or updates all fields in the view.
-
updateViewField
Creates or updates a field in the View.This will update or create and bind widgets in the template to represent the field. To create the form widget that implements the editing, it calls
createFormWidget()
.The default behaviour interprets
WFormModel#isVisible()
,WFormModel#isReadOnly()
,WFormModel#label()
andWFormModel#getValidator()
to update the View, and callsupdateViewValue()
to update the view value. If no form widget has been set for the givenfield
usingsetFormWidget()
, then it callscreateFormWidget()
to try to create one.It's usually more convenient to reimplement
updateViewValue()
to override specifically how the value from the model should be used to update the form widget. -
updateViewValue
Updates the value in the View.The default implementation calls updateViewValue(
WFormModel
*, WFormField::Field,WWidget
*). If this function returnedfalse
, it setsWFormModel#valueText()
intoWFormWidget#setValueText()
. -
updateViewValue
Updates the value in the View.The default implementation considers only a specialized update function that may have been configured in
setFormWidget()
and returnsfalse
if no such function was configured. -
updateModel
Updates the Model.This creates or updates all field values in the model.
-
updateModelField
Updates a field in the Model.This calls
updateModelValue()
to update the model value. -
updateModelValue
Updates a value in the Model.The default implementation calls updateModelValue(
WFormModel
*, WFormModel::Field,WWidget
*), and if that returnsfalse
, it then callsWFormModel#setValue()
withWFormWidget.getValueText()
. -
updateModelValue
Updates a value in the Model.The default implementation considers only a specialized update function that may have been configured in
setFormWidget()
and returnsfalse
if no such function was configured. -
createFormWidget
Creates a form widget.This method is called by
updateViewField()
when it needs to create a form widget for a field, and none was specified usingsetFormWidget()
. -
indicateValidation
protected void indicateValidation(String field, boolean validated, WText info, WWidget edit, WValidator.Result validation) Indicates the validation result.The default implementation calls
WTheme#applyValidationStyle()
Note: We changed the signature to take an edit
WWidget
instead ofWFormWidget
in JWt 3.3.1!
-