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.
contentsUpdatedAttributes attribute changes or when the model specifically sends the event.
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.
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:
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.
contentsUpdatedAttributes attribute to include the key attributes.
sashelp.classes.staticStringList.intrface so that you do not have to create a new interface.
items attribute on the model.
sashelp.fsp.Object.class and whose description is My Model.
sasuser.myclasses.myModel.class.
sashelp.classes.staticStringList.intrface for the interface and set Status to Supports.
items and assign it as a List type. Save the class.
sasuser.myclasses.myModel.scl that is created for
you:useclass sasuser.myclasses.myModel.class; /* Override of _init method */ init: public method (state="0"); dcl num rc; dcl list temp=makelist(); _super(); rc=clearlist(items); temp=items; rc=insertc(temp, 'One', -1); rc=insertc(temp, 'Two', -1); rc=insertc(temp, 'Three', -1); items=temp; endmethod; getItems: public method return=list; return(items); endmethod; enduseclass;Compile the code, and then close the Source window and return to the Class Editor.
sasuser.myclasses.myModel.class.
My Interface.
sasuser.myclasses.MyInterface.intrface.
interface sasuser.myclasses.MyInterface; getColumnData: public method return=list; endinterface;You can use the SAVECLASS command to save the SCL code as an interface. For more information, see SAS Component Language Reference.
sashelp.fsp.Object.class and whose description is Column Data Model.
sasuser.myclasses.ColumnDataModel.class.
sasuser.myclasses.myInterface.intrface) for the interface and set Status to Supports.
columnData and assign it as a List type. Add an attribute named table and assign it as a Character
type. Add a third attribute named columnName and assign it as a Character type.
contentsUpdatedAttributes, and
then select Override from the pop-up menu.
Select the Initial Value cell, and then click the ellipsis button
(...) to edit the values. In the dialog box, select columnName and table, and then click OK.
sasuser.myclasses.ColumnDataModel.scl that is created
for you:useclass sasuser.myclasses.ColumnDataModel.class;
getColumnData: public method
return=list;
dcl num rc dsid levels;
/* reset the existing items attribute */
rc=clearlist(columnData);
/* open the SAS table specified in the table attribute */
dsid = open (table);
if dsid ne 0 then do; /* process if table exists */
if varnum (dsid, columnName) > 0 then do;
levels=0;
rc=lvarlevel(dsid,columnName,levels,columnData);
rc=revlist(columnDataModel);
end;
end;
rc=close(dsid);
return(columnData);
endmethod;
enduseclass;Compile and save the SCL code, and then
close the Source window and return to the
Class Editor.
sashelp.classes.listbox_c.class). Name your class My List Box.
sasuser.myclasses.myListBox.class.
Override from the pop-up menu. Select the _setcamModel method, and then right-click
and select Override from the pop-up
menu. Right-click and select New Method from the pop-up menu, and then add a method named getModelData. Right-click and select Source from the pop-up menu to add the following SCL code, which implements all three methods:useclass sasuser.myclasses.myListBox.class; getModelData: public method; /* This method retrieves the data from the model. */ /* modelID is an attribute inherited from Object */ /* that contains the identifier of the model when */ /* the viewer's model attribute is set. */ items=modelID.getColumnData(); endmethod; onContentsUpdated: public method colItems:char; getModelData(); endmethod; setcamModel: protected method attributeValue:update:char return=num; _super(attributeValue); getModelData(); endmethod; enduseclass;Compile the SCL and save the entry.
sasuser.myclasses.ColumnDataModel.class and sasuser.myclasses.myListBox.class.
table and columnName attributes on the model. Use the Properties window to set columnDataModel1's table attribute to a valid SAS table such as sashelp.prdsale. Set columnDataModel1's columnName attribute to a valid column name in the
table. For example, Region is a column in the sashelp.prdsale table.