The following items describe
the flow of control for model/view communication:
-
When the
model
attribute of a viewer is set, an event handler
is established on the viewer to listen for the “contents updated”
event to be sent from the model. The event handler is the _onContentsUpdated
method. In addition, the _setcamModel method executes when the viewer's
model
attribute is set, both at build time and at
run time. The _setcamModel method includes a call to a method that
is both implemented on the model and defined in the interface.
-
The “contents
updated” event is sent by the model when one of the attributes
in its
contentsUpdatedAttributes
attribute
changes or when the model specifically sends the event.
The model's
contentsUpdatedAttributes
attribute contains the
name of one or more other attributes. These attributes have been identified
as critical components on the component. They affect the contents
of the model, and the viewer must be notified when their values change.
The “contents Updated” event passes the name of the
changed attribute as an input argument to the _onContentsUpdated method.
-
The viewer's event handler,
which is the _onContentsUpdated method, calls back to the model to
retrieve updated information. The viewer is able to communicate with
the model due to the methods defined in the interface.
For example, consider
a frame that has a list box control that you want to use to present
a list of standard color names (such as Red, Green, and Blue). The
Color List Model component provides this list of names based on values
that are supported by SAS software. You can establish a model/view
relationship between a list box and an instance of the Color List
Model component by dragging the model from the Component window and
dropping it onto the list box in the frame.
At the point where the
drop occurs on the list box, the
SAS/AF classes have been designed to verify whether the two
objects know how to communicate with each other via model/view communication
using a common interface. If the model has a supported interface that
matches a required interface on the viewer, the model is “attached”
to the viewer. In this case, the color list model supports the
sashelp.classes.staticStringList
interface, and the
list box requires the same interface, so a model/view relationship
exists. Two types of processing occur once the model/view relationship
is established:
-
The
model
attribute on the viewer is set to the name of the model, which executes
the setCAM for the attribute (_setcamModel). In the list box/color
list model example, the implementation of the _setcamModel method
for the list box contains code that queries the model and retrieves
a list of items using a _getItems call, which is a supported method
in the interface. The CAM then sets the value of the viewer's
items
attribute to the list that is returned by _getItems.
-
When the “contents
Updated” event is sent by the model, the viewer's _onContentsUpdated
method executes. This method's implementation is similar to the _setcamModel
in that it queries the model using methods supplied in the interface,
and it retrieves the model's information to update the viewer. In
the list box example, a _getItems call is used to retrieve the list
of colors each time the model is updated.