Wt  3.2.2
Public Member Functions | Protected Member Functions
Wt::WTemplateFormView Class Reference

A template-based View class form form models. More...

#include <Wt/WTemplateFormView>

Inheritance diagram for Wt::WTemplateFormView:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 WTemplateFormView (WContainerWidget *parent=0)
 Constructor.
 WTemplateFormView (const WString &text, WContainerWidget *parent=0)
 Constructor.
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 value in the Model.
virtual void updateView (WFormModel *model)
 Updates the View.
virtual void updateModel (WFormModel *model)
 Updates the Model.

Protected Member Functions

virtual WFormWidgetcreateFormWidget (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.

Detailed Description

A template-based View class form 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_);
   }
 }

Member Function Documentation

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. You either need to make sure these widgets have been created and bound before calling updateView(), or you need to specialize this method to do it on-demand.

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::updateModel ( WFormModel model) [virtual]

Updates the Model.

This creates or updates all field values in the model.

See also:
updateModelField(), WFormModel::fields()
void Wt::WTemplateFormView::updateModelField ( WFormModel model,
WFormModel::Field  field 
) [virtual]

Updates a field value in the Model.

This propagates data entered in the form widget to the model with WFormModel::setValue()

void Wt::WTemplateFormView::updateView ( WFormModel model) [virtual]

Updates the View.

This creates or updates all fields in the view.

See also:
updateViewField(), WFormModel::fields()
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().

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator

Generated on Fri Jul 27 2012 for the C++ Web Toolkit (Wt) by doxygen 1.7.5.1