Class WTemplateFormView
- java.lang.Object
-
- eu.webtoolkit.jwt.WObject
-
- eu.webtoolkit.jwt.WWidget
-
- eu.webtoolkit.jwt.WWebWidget
-
- eu.webtoolkit.jwt.WInteractWidget
-
- eu.webtoolkit.jwt.WTemplate
-
- eu.webtoolkit.jwt.WTemplateFormView
-
- Direct Known Subclasses:
AuthWidget,RegistrationWidget,UpdatePasswordWidget
public class WTemplateFormView extends WTemplate
A template-based View class for form models.This implements a View to be used in conjunction with
WFormModelmodels 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()andupdateModelField()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 theupdateModel()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.Okbutton 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_, noDefault
-
Fields inherited from class eu.webtoolkit.jwt.WWidget
WT_GETEXTRAMS_JS
-
-
Constructor Summary
Constructors Constructor Description WTemplateFormView()Constructor.WTemplateFormView(WContainerWidget parentContainer)Constructor.WTemplateFormView(java.lang.CharSequence text)Constructor.WTemplateFormView(java.lang.CharSequence text, WContainerWidget parentContainer)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected WWidgetcreateFormWidget(java.lang.String field)Creates a form widget.protected voidindicateValidation(java.lang.String field, boolean validated, WText info, WWidget edit, WValidator.Result validation)Indicates the validation result.voidsetFormWidget(java.lang.String field, WWidget formWidget)Sets the form widget for a given field.voidsetFormWidget(java.lang.String field, WWidget formWidget, java.lang.Runnable updateViewValue, java.lang.Runnable updateModelValue)Sets the form widget for a given field.voidupdateModel(WFormModel model)Updates the Model.voidupdateModelField(WFormModel model, java.lang.String field)Updates a field in the Model.voidupdateModelValue(WFormModel model, java.lang.String field, WFormWidget edit)Updates a value in the Model.booleanupdateModelValue(WFormModel model, java.lang.String field, WWidget edit)Updates a value in the Model.voidupdateView(WFormModel model)Updates the View.voidupdateViewField(WFormModel model, java.lang.String field)Creates or updates a field in the View.voidupdateViewValue(WFormModel model, java.lang.String field, WFormWidget edit)Updates the value in the View.booleanupdateViewValue(WFormModel model, java.lang.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, render, 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, hideToolTip, isCanReceiveFocus, isDisabled, isHidden, isHiddenKeepsGeometry, isInline, isLoaded, isPopup, isRendered, isScrollVisibilityEnabled, isScrollVisible, isSetFirstFocus, isThemeStyleEnabled, isVisible, jsStringLiteral, jsStringLiteral, manageWidget, parentResized, parentResized, propagateSetVisible, removeScript, removeStyleClass, 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, showToolTip, showToolTipOnHover, unescapeText, updateSignalConnection, voidEventSignal, widgetAdded, widgetRemoved
-
Methods inherited from class eu.webtoolkit.jwt.WWidget
acceptDrops, acceptDrops, addCssRule, addCssRule, addJSignal, addStyleClass, animateHide, animateShow, applyThemeStyles, boxBorder, boxPadding, createJavaScript, disable, dropEvent, enable, getDropTouch, getJsRef, getParent, hide, htmlText, isExposed, isGlobalWidget, isLayoutSizeAware, 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, tr
-
Methods inherited from class eu.webtoolkit.jwt.WObject
getObjectName, setFormData
-
-
-
-
Constructor Detail
-
WTemplateFormView
public WTemplateFormView(WContainerWidget parentContainer)
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
public WTemplateFormView(java.lang.CharSequence text, WContainerWidget parentContainer)Constructor.For convenience, this initializes the template with:
addFunction("id", Functions.id); addFunction("tr", Functions.tr); addFunction("block", Functions.block);
-
WTemplateFormView
public WTemplateFormView(java.lang.CharSequence text)
Constructor.
-
-
Method Detail
-
setFormWidget
public void setFormWidget(java.lang.String field, WWidget formWidget)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(java.lang.String field, WWidget formWidget, java.lang.Runnable updateViewValue, java.lang.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
public void updateView(WFormModel model)
Updates the View.This creates or updates all fields in the view.
-
updateViewField
public void updateViewField(WFormModel model, java.lang.String field)
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
public void updateViewValue(WFormModel model, java.lang.String field, WFormWidget edit)
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
public boolean updateViewValue(WFormModel model, java.lang.String field, WWidget edit)
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
public void updateModel(WFormModel model)
Updates the Model.This creates or updates all field values in the model.
-
updateModelField
public void updateModelField(WFormModel model, java.lang.String field)
Updates a field in the Model.This calls
updateModelValue()to update the model value.
-
updateModelValue
public void updateModelValue(WFormModel model, java.lang.String field, WFormWidget edit)
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
public boolean updateModelValue(WFormModel model, java.lang.String field, WWidget edit)
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
protected WWidget createFormWidget(java.lang.String field)
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(java.lang.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!
-
-