12.07.2015 Views

Using Zen Components - InterSystems Documentation

Using Zen Components - InterSystems Documentation

Using Zen Components - InterSystems Documentation

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Model View ControllerIn the exercise “Binding a to an Object Data Model,” during “Step 4: Saving the Form,” you added Save functionalityby causing the %OnSaveSource method to set the %id property of the model to the ID of the saved object, asfollows:Method %OnSaveSource(pSource As ZENDemo.Data.Patient) As %Status{Set tSC=pSource.%Save()If $$$ISOK(tSC) Set ..%id=pSource.%Id()Quit tSC}As a result, every time the user clicks New, enters values, then clicks Save, the form shows the newly assigned ID to theuser (thanks to the dataBinding on that field). Of course, this only works if the data entered in the form passes validation.Name is a required field, so if no Name is entered, the record is not saved.6.6.2.2 DeleteSuppose the user clicks Delete. The data controller’s deleteId method expects to receive an input argument containing theID for the record to be deleted. Therefore, when the user clicks Delete, the page uses the data controller’s getModelIdmethod to determine the ID of the record the user is currently viewing. It passes this ID on to deleteId. This (eventually)leads to a call to the data model’s %OnDeleteSource method on the server. The source object is deleted, and since therewill be no source object anymore, the page calls the data controller’s createNewObject method to empty the form andprepare it for new input.Although the code examples in this chapter do not take advantage of this feature, the deleteId method returns a Booleanvalue, true or false. It is true if it successfully deleted the record. It is false if it failed, or if the data controller or its datamodel are read-only. A data controller is read-only if its readOnly attribute is set to 1 (true). A data model is read-only ifits class parameter is set to 1 (true).Important:If, while using this exercise, you delete a record with a specific ID, this object no longer exists. You cannotview or create a record with this ID again.6.6.2.3 UpdateBefore clicking Update, the user must enter an ID number (between 1 and 1000) in the ID field. The page updates the formfields with data from that record. This fails only if you have previously deleted a record with that ID.6.6.2.4 ErrorsA data controller has a server-side property called modelError that is a string containing the most recent error message thatthe data controller encountered while saving, loading, deleting, or invoking a server-side action. A data controller also hasa client-side JavaScript method, getError, that an application can invoke to get the modelError value. getError has noarguments and returns the modelError string. It returns an empty string '' if there is no current error.6.7 with an Object Data ModelThis topic explains how to use with a data controller. In this case the data model is an object data model.6.7.1 Step 1: is EasyYou may create your first very easily as follows:168 <strong>Using</strong> <strong>Zen</strong> <strong>Components</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!