A template-based View class form models. More...
#include <Wt/WTemplateFormView>

Public Member Functions | |
| WTemplateFormView (WContainerWidget *parent=0) | |
| Constructor. | |
| WTemplateFormView (const WString &text, WContainerWidget *parent=0) | |
| Constructor. | |
| void | setFormWidget (WFormModel::Field field, WWidget *widget) |
| Sets the form widget for a given field. | |
| void | setFormWidget (WFormModel::Field field, WWidget *widget, const boost::function< void()> &updateViewValue, const boost::function< void()> &updateModelValue) |
| Sets the form widget for a given field. | |
| virtual void | updateView (WFormModel *model) |
| Updates the View. | |
| virtual void | updateViewField (WFormModel *model, WFormModel::Field field) |
| Creates or updates a field in the View. | |
| virtual void | updateViewValue (WFormModel *model, WFormModel::Field field, WFormWidget *edit) |
| Updates the value in the View. | |
| virtual bool | updateViewValue (WFormModel *model, WFormModel::Field field, WWidget *edit) |
| Updates the value in the View. | |
| virtual void | updateModel (WFormModel *model) |
| Updates the Model. | |
| virtual void | updateModelField (WFormModel *model, WFormModel::Field field) |
| Updates a field in the Model. | |
| virtual void | updateModelValue (WFormModel *model, WFormModel::Field field, WFormWidget *edit) |
| Updates a value in the Model. | |
| virtual bool | updateModelValue (WFormModel *model, WFormModel::Field field, WWidget *edit) |
| Updates a value in the Model. | |
Protected Member Functions | |
| virtual WWidget * | createFormWidget (WFormModel::Field field) |
| Creates a form widget. | |
| virtual void | indicateValidation (WFormModel::Field field, bool validated, WText *info, WWidget *edit, const WValidator::Result &validation) |
| Indicates the validation result. | |
A template-based View class form models.
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 placholder variables to represent the label, editor, and validation messages in the template. For a field name 'field', we have:
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 Ok button and do:
void MyView::okClicked() { updateModel(model_); if (model_->validate()) { ... } else { updateView(model_); } }
| Wt::WTemplateFormView::WTemplateFormView | ( | WContainerWidget * | parent = 0 | ) |
Constructor.
For convenience, this initializes the template with:
addFunction("id", &Functions::id); addFunction("tr", &Functions::tr); addFunction("block", &Functions::block);
| Wt::WTemplateFormView::WTemplateFormView | ( | const WString & | text, |
| WContainerWidget * | parent = 0 |
||
| ) |
Constructor.
For convenience, this initializes the template with:
addFunction("id", &Functions::id); addFunction("tr", &Functions::tr); addFunction("block", &Functions::block);
| WWidget * Wt::WTemplateFormView::createFormWidget | ( | WFormModel::Field | field | ) | [protected, virtual] |
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 using setFormWidget().
Reimplemented in Wt::Auth::AuthWidget, Wt::Auth::RegistrationWidget, and Wt::Auth::UpdatePasswordWidget.
| void Wt::WTemplateFormView::indicateValidation | ( | WFormModel::Field | field, |
| bool | validated, | ||
| WText * | info, | ||
| WWidget * | edit, | ||
| const WValidator::Result & | validation | ||
| ) | [protected, virtual] |
Indicates the validation result.
The default implementation calls WTheme::applyValidationStyle()
| void Wt::WTemplateFormView::setFormWidget | ( | WFormModel::Field | field, |
| Wt::WWidget * | formWidget | ||
| ) |
Sets the form widget for a given field.
When the widget is a form widget, then the View class will use WFormWidget::setValueText() to update it with model values, and WFormWidget::valueText() 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 reimplement updateViewValue() or updateModelValue().
| void Wt::WTemplateFormView::setFormWidget | ( | WFormModel::Field | field, |
| WWidget * | widget, | ||
| const boost::function< void()> & | updateViewValue, | ||
| const boost::function< void()> & | 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.
| void Wt::WTemplateFormView::updateModel | ( | WFormModel * | model | ) | [virtual] |
Updates the Model.
This creates or updates all field values in the model.
| void Wt::WTemplateFormView::updateModelField | ( | WFormModel * | model, |
| WFormModel::Field | field | ||
| ) | [virtual] |
Updates a field in the Model.
This calls updateModelValue() to update the model value.
| void Wt::WTemplateFormView::updateModelValue | ( | WFormModel * | model, |
| WFormModel::Field | field, | ||
| WFormWidget * | edit | ||
| ) | [virtual] |
Updates a value in the Model.
The default implementation calls updateModelValue(WFormModel *, WFormModel::Field, WWidget *). If this function returned false, it calls WFormModel::setValue() with WFormWidget::valueText().
| bool Wt::WTemplateFormView::updateModelValue | ( | WFormModel * | model, |
| WFormModel::Field | field, | ||
| WWidget * | edit | ||
| ) | [virtual] |
Updates a value in the Model.
The default implementation considers only a specialized update function that may have been configured in setFormWidget() and returns false if no such function was configured.
| void Wt::WTemplateFormView::updateView | ( | WFormModel * | model | ) | [virtual] |
Updates the View.
This creates or updates all fields in the view.
| void Wt::WTemplateFormView::updateViewField | ( | WFormModel * | model, |
| WFormModel::Field | field | ||
| ) | [virtual] |
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() and WFormModel::validator() to update the View, and calls updateViewValue() to update the view value. If no form widget has been set for the given field using setFormWidget(), then it calls createFormWidget() 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.
| void Wt::WTemplateFormView::updateViewValue | ( | WFormModel * | model, |
| WFormModel::Field | field, | ||
| WFormWidget * | edit | ||
| ) | [virtual] |
Updates the value in the View.
The default implementation calls updateViewValue(WFormModel *, WFormField::Field, WWidget *). If this function returned false, it sets WFormModel::valueText() into WFormWidget::setValueText().
| bool Wt::WTemplateFormView::updateViewValue | ( | WFormModel * | model, |
| WFormModel::Field | field, | ||
| WWidget * | edit | ||
| ) | [virtual] |
Updates the value in the View.
The default implementation considers only a specialized update function that may have been configured in setFormWidget() and returns false if no such function was configured.
1.7.6.1