Wt
3.3.0
|
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, WFormWidget *formWidget) |
Sets the form widget for a given field. | |
void | setFormWidget (WFormModel::Field field, WFormWidget *formWidget, const boost::function< void()> &updateViewValue, const boost::function< void()> &updateModelValue) |
Sets the form widget for a given field. | |
virtual void | updateViewField (WFormModel *model, WFormModel::Field field) |
Creates or updates a field in the View. | |
virtual void | updateModelField (WFormModel *model, WFormModel::Field field) |
Updates a field in the Model (Deprecated) | |
virtual void | updateViewValue (WFormModel *model, WFormModel::Field field, WFormWidget *edit) |
Updates the value in the View. | |
virtual void | updateModelValue (WFormModel *model, WFormModel::Field field, WFormWidget *edit) |
Updates a value in the Model. | |
virtual void | updateView (WFormModel *model) |
Updates the View. | |
virtual void | updateModel (WFormModel *model) |
Updates the Model. | |
Protected Member Functions | |
virtual WFormWidget * | createFormWidget (WFormModel::Field field) |
Creates a form widget. | |
virtual void | indicateValidation (WFormModel::Field field, bool validated, WText *info, WFormWidget *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 a model field, it uses a number of conventional variable names to represent the label, editor, and validation messages in the template:
For a field with name 'field', a typical template uses blocks of the following-format:
* ${<if:field>} * <label for="${id:field}">${field-label}</label> * ${field} ${field-info} * ${</if:field>} *
The View may render fields of more than one model, and does not necessarily need to render all information of each model: you can call the updateViewField() and updateModelField() for individual model fields.
The updateView() method updates the view based on a model (e.g. to propagate changed values or validation), while the updateModel() method updates a 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_); } }
WFormWidget * 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, | ||
WFormWidget * | edit, | ||
const WValidator::Result & | validation | ||
) | [protected, virtual] |
Indicates the validation result.
The default implementation will set "Wt-valid" or "Wt-invalid" on the form widget, and "Wt-error" on the info text.
void Wt::WTemplateFormView::setFormWidget | ( | WFormModel::Field | field, |
WFormWidget * | formWidget, | ||
const boost::function< void()> & | updateViewValue, | ||
const boost::function< void()> & | updateModelValue | ||
) |
Sets the form widget for a given field.
This also defines the functions to update the view respectively the model
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 (Deprecated)
Calls updateModelValue()
void Wt::WTemplateFormView::updateModelValue | ( | WFormModel * | model, |
WFormModel::Field | field, | ||
WFormWidget * | edit | ||
) | [virtual] |
Updates a value in the Model.
The default implementation sets WFormModel::setValue() with WFormWidget::valueText().
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().
void Wt::WTemplateFormView::updateViewValue | ( | WFormModel * | model, |
WFormModel::Field | field, | ||
WFormWidget * | edit | ||
) | [virtual] |
Updates the value in the View.
The default implementation sets WFormModel::valueText() into WFormWidget::setValueText()