pp108 : View

View

The View object is a virtual block of data from a model. The following are the functions of the View object:

  • Exposes and allows the modification of data from a model using controls.
  • Enables the navigation of the dataset through the navigator object.
  • Notifies the model to retrieve more business objects when navigating. For information, refer to Model.

In an MVC pattern, there can be multiple views attached to a model. When data in a view is modified, the controller notifies the change to the model. The model then updates its business object and fires an event, which keeps all the views refreshed with the latest data.

A view is, in general, a template of the control to which the model is bound. It is a runtime property that can be retrieved by registering a control to a model as follows:

var newView = newModel.registerUIComponent(htmlElement, 3);

In the above example, the second parameter is the size for the view created.

Views can be single-occurrence and multi-occurrence. In single-occurrence views, the size is always one. In multi-occurrence views, there can be several properties and run-time objects such as navigator (which is a default object for all grouping controls such as Table, Groupbox, and Tab).

It is possible to have more than one view in a single XForm using the MVC pattern. However, it is also possible to have views in different windows, and yet manage to have the same model for both the XForms. The following example displays the grid view and the form view (detail view) in separate XForms.

  • Have a multi occurrence view of the Employees table data and provide a link to open the single occurrence view of Employees information in a window while clicking on the EmployeeID. The following code sends the model and the current selected tuple's index as parameter to the opening window:
    var data = new Object();
    data.model = EmployeesModel;
    data.locator = event.srcElement.tupleIndex //Each HTML element has a tupleIndex property
    application.select(singleOccuranceApplication.XMLDocument.documentElement, data);
    
  • In the init-done event of the single occurrence page, get the model and refresh the HTML element with the locator sent as parameter.
    var EmployeesModel = event.data.model;
    EmployeesModel.registerUIComponent(EmployeesGroup); //EmployeesGroup is the single occurrence view
    EmployeesGroup.refreshRenderer(event.data.locator);
    

Each view has a renderer attached to it, which is responsible for rendering the data as HTML. Whenever a change occurs in the data of the view, the renderer fires the onchange listener events and updates the business object in the model accordingly.

Properties and Methods of the View Object

Table 1. List of Properties

Runtime property

Description

model

Retrieves the Model object associated to the view.

navigator

Retrieves an object through which the Control bar and Pagination bar  button objects can be accessed at runtime.

size

Retrieves the integer that denotes the size of the view. The size of a view is determined based on the type of control and its anchor settings. When anchored, the size of a table control changes and it is re-positioned according to the space available on the XForm. For a Groupbox control, the size is always 1.

Table 2. List of Methods

Method

Description

createNewObjectInstance()

This method creates a new object instance.

getActiveNode()

This method returns the node that is currently bound to the view.

getNodeset()

This method returns a collection of the nodes that are bound to the view. In case of a transactional model, it returns a collection of tuples.

refreshRenderer

This method refreshes the controls in the view with the value specified for locator.

validateObjectInstances()

This method validates data in all object instances of the view, with the validation conditions set for the controls in view. It returns True if the validation is successful; otherwise, it returns False .

 

 

Related reference

View