Class WTemplateFormView

Direct Known Subclasses:
AuthWidget, RegistrationWidget, UpdatePasswordWidget

public class WTemplateFormView
extends WTemplate
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:

  • '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 Ok button and do:


 void okClicked()
 {
 updateModel(this.model);
 if (this.model.validate()) {
 ...
 } else {
 updateView(this.model);
 }
 }

 
  • Constructor Details

    • WTemplateFormView

      public WTemplateFormView​(WContainerWidget parent)
      Constructor.

      For convenience, this initializes the template with:

      
       addFunction("id", Functions.id);
       addFunction("tr", Functions.tr);
       addFunction("block", Functions.block);
      
       
    • WTemplateFormView

      public WTemplateFormView()
      Constructor.

      Calls this((WContainerWidget)null)

    • WTemplateFormView

      public WTemplateFormView​(java.lang.CharSequence text, WContainerWidget parent)
      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)
  • Method Details