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.FunctionsNested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData -
Field Summary
Fields inherited from class eu.webtoolkit.jwt.WInteractWidget
dragTouchEndSlot_, dragTouchSlot_, noDefaultFields inherited from class eu.webtoolkit.jwt.WWidget
WT_GETEXTRAMS_JS -
Constructor Summary
ConstructorsConstructorDescriptionConstructor.WTemplateFormView(WContainerWidget parentContainer) Constructor.Constructor.WTemplateFormView(CharSequence text, WContainerWidget parentContainer) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected WWidgetcreateFormWidget(String field) Creates a form widget.protected voidindicateValidation(String field, boolean validated, WText info, WWidget edit, WValidator.Result validation) Indicates the validation result.voidsetFormWidget(String field, WWidget formWidget) Sets the form widget for a given field.voidsetFormWidget(String field, WWidget formWidget, Runnable updateViewValue, Runnable updateModelValue) Sets the form widget for a given field.voidupdateModel(WFormModel model) Updates the Model.voidupdateModelField(WFormModel model, String field) Updates a field in the Model.voidupdateModelValue(WFormModel model, String field, WFormWidget edit) Updates a value in the Model.booleanupdateModelValue(WFormModel model, String field, WWidget edit) Updates a value in the Model.voidupdateView(WFormModel model) Updates the View.voidupdateViewField(WFormModel model, String field) Creates or updates a field in the View.voidupdateViewValue(WFormModel model, String field, WFormWidget edit) Updates the value in the View.booleanupdateViewValue(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, varNameMethods 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, render, setDraggable, setDraggable, setDraggable, setDraggable, setMouseOverDelay, setPopup, touchEnded, touchMoved, touchStarted, unsetDraggableMethods inherited from class eu.webtoolkit.jwt.WWebWidget
addStyleClass, anchorAt, becomePositionAnchor, beingDeleted, blurred, callJavaScriptMember, childrenChanged, createDomElement, doJavaScript, escapeText, escapeText, escapeText, escapeText, find, findById, focussed, formDataChanged, getAttributeValue, getBaseZIndex, getChildren, getClearSides, getDecorationStyle, getDomChanges, getFloatSide, getHeight, getHtmlTagName, getId, getJavaScriptMember, getLineHeight, getMargin, getMaximumHeight, getMaximumWidth, getMinimumHeight, getMinimumWidth, getOffset, getPositionAnchor, getPositionAnchorName, getPositionScheme, getScrollVisibilityMargin, getStyleClass, getTabIndex, getToolTip, getVerticalAlignment, getVerticalAlignmentLength, getWidth, hasFocus, hasStyleClass, hideToolTip, isCanReceiveFocus, isDefaultNativeControl, isDisabled, isHidden, isHiddenKeepsGeometry, isInline, isLoaded, isPopup, isRendered, isScrollVisibilityEnabled, isScrollVisible, isSetFirstFocus, isThemeStyleEnabled, isVisible, jsStringLiteral, jsStringLiteral, manageWidget, parentResized, parentResized, propagateSetVisible, removeScript, removeStyleClass, resendFormData, resize, scrollVisibilityChanged, setAttributeValue, setBaseZIndex, setCanReceiveFocus, setClearSides, setDecorationStyle, setDefaultNativeControl, setDeferredToolTip, setDisabled, setFlexBox, setFloatSide, setFocus, setHidden, setHiddenKeepsGeometry, setHtmlTagName, setId, setInline, setJavaScriptMember, setLineHeight, setLoadLaterWhenInvisible, setMargin, setMaximumSize, setMinimumSize, setObjectName, setOffsets, setParentWidget, setPositionAnchor, setPositionAnchor, setPositionScheme, setScrollVisibilityEnabled, setScrollVisibilityMargin, setSelectable, setStyleClass, setTabIndex, setThemeStyleEnabled, setToolTip, setVerticalAlignment, showToolTip, showToolTipOnHover, unescapeText, updateSignalConnection, voidEventSignal, widgetAdded, widgetRemovedMethods inherited from class eu.webtoolkit.jwt.WWidget
acceptDrops, acceptDrops, addCssRule, addCssRule, addJSignal, addStyleClass, anchorAt, animateHide, animateShow, applyThemeStyles, boxBorder, boxPadding, createJavaScript, disable, dropEvent, enable, getDropTouch, getJsRef, getParent, hide, htmlText, htmlText, isExposed, isGlobalWidget, isLayoutSizeAware, isPositionAnchor, layoutSizeChanged, needsRerender, positionAt, positionAt, positionAt, positionAt, removeFromParent, removeStyleClass, render, resize, scheduleRender, scheduleRender, scheduleRender, scheduleThemeStyleApply, setClearSides, setDeferredToolTip, setFocus, setHeight, setHidden, setLayoutSizeAware, setMargin, setMargin, setMargin, setMargin, setMargin, setOffsets, setOffsets, setOffsets, setOffsets, setOffsets, setToolTip, setVerticalAlignment, setWidth, show, stopAcceptDrops, toggleStyleClass, toggleStyleClass, trMethods 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
widgetis 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.
- See Also:
-
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 givenfieldusingsetFormWidget(), 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 returnsfalseif no such function was configured. -
updateModel
Updates the Model.This creates or updates all field values in the model.
- See Also:
-
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 returnsfalseif 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
WWidgetinstead ofWFormWidgetin JWt 3.3.1!
-