Skip to main content

This is documentation for Caché & Ensemble. See the InterSystems IRIS version of this content.

For information on migrating to InterSystems IRIS, see Why Migrate to InterSystems IRIS?

Creating the Model Class: Methods cont.

Finally, we add two more methods to the model class. These methods do the actual work of loading data from the data source into the model's properties and then saving the data from the model's properties back to the data source.

Add the following methods to MVFILE.PersonPage.cls and then compile the class.

  1. 
    Method %OnLoadModel(pSource As MVFILE.PERSON) As %Status
    {
    @ME->ItemId = pSource->ItemId
    @ME->Name = pSource->Name
    @ME->Hair = pSource->Hair
    @ME->Age = pSource->Age
    IF ISOBJECT(pSource->Phone) THEN
    FOR I=1 TO pSource->Phone->Count()
      @ME->Phones = @ME->Phones:pSource->Phone->GetAt(I):" "
    NEXT I 
    END
    Return "%SYSTEM.Status"->OK()
    } 
    

    This method loads data from the data source into the model.

  2. 
    Method %OnStoreModel(pSource As MVFILE.PERSON) As %Status
    { 
    pSource->ItemId = @ME->ItemId 
    pSource->Name = @ME->Name
    pSource->Hair = @ME->Hair
    pSource->Age = @ME->Age
    pSource->Phone->Clear()
    FOR I=1 to DCOUNT(@ME->Phones," ")
      pSource->Phone->InsertAt(FIELD(@ME->Phones," ",I),I)
    NEXT I
    Return pSource->%Save()
    }                 
    

    This method saves the data from the model to the data source.

Feedback