Data Binding

Use

To make programming easier for you with the MVC design, the framework for the model of an application provides you with basic class CL_BSP_MODEL, which you can use in your own model class as a class that passes on its properties. The model class represents the data context of your application and, as a result, receives a copy of the data (or references to the data) that are relevant for the view from the database model.

The model class provides:

  • The data used for the views, with the corresponding type and data Dictionary information.

  • Input conversions

  • Information about input errors that occurred for which data

A controller can instantiate a model class or even several model classes (see also Calling the Model Class Using the Controller). The controller has a list of all model instances, analogous to the list of subcontrollers.

The controller assigns unique IDs to each model instance.

Data binding is particularly important with HTMLB extension elements inputField and label (see also the documentation for these elements in the system). It is also implemented for HTMLB elements dropdownListBox, radioButtonGroup, checkbox, textEdit, and tableView.

A model class can either be designed quite simply or it can be used with more complex application cases.

Simple Model Class

Data binding is important for transmitting values for output data. Add the data that is required by the view to your model class as attributes. These attributes are all from the visibility range public and can be as follows:

  • Simple variables

  • Structures

  • Tables

In the most simple case, the model class has these attributes only and so can easily be used for data binding as part of a BSP application.

This type of simple model class provides the following functionality:

  • The controller can create a model instance and initialize the attributes, since they are public attributes.

  • The controller transmits a reference to the model instance to the view.

  • The data binding to the model is specified in the view for each view element using a path expression ( //…).

If necessary you can also add your own methods to your model class for further processing attributes.

Complex Model Class

It is possible that simple model classes are not sufficient for your requirements. This may be the case, for example, if you are working with generic data or if you need special methods for setting ( SET) and getting ( GET) attributes. You can therefore use these methods to determine your own implementations that are important for your specific application.

In these types of applications, the base class contains copy templates for the setter and getter methods: _SET_<Attribute> and _GET_<Attribute>. All of these templates begin with _. The naming conventions for the actual methods are as follows:

Naming convention for setter methods:

SET_<Attribut> for a field

SET_S_<Attribut> for a structure

SET_T_<Attribut> for a table

          


            

Naming convention for getter methods:

GET_<Attribut> for a field

GET_S_<Attribut> for a structure

GET_T_<Attribut> for a table

As soon as a setter or a getter method is set, it is used automatically.

Data binding is automatically available because the name is the same. In method DO_HANDLE_DATA (see also Process Flow) of class CL_BSP_CONTROLLER2 all controllers automatically fill the form fields with data.

The path specifications for the model data have the following syntax:

  • Simple field attribute

    value="//<field name>"

  • Structure attribute

    value="//<structure name>.<field name>"

  • Table attribute

    value="//<table name>[<line index>].<field name>"