To create departments, we will add another button with the label, New. This will create a new department that is placed into the variable part. Do the following:
To create new departments, you will need to add a Text part, and a label, Department, for the department attribute. After you have added the Text part and label for department, connect the Text part's object attribute to the department attribute of the TstDepartment1 variable.
Test the view as follows:
As before, if we create the department (click New) without saving it (click Save), the department will not be added because the transaction would not have been committed.
The next step is to get the list of departments to refresh each time we add or change a department. Also, we should ensure that the department itself cannot be changed when we are editing a department. This is because the department is the attribute we defined as the object identifier (OID) in the Map Browser, and it is the effective key of the department business object. Changing the key of a business object is not permitted once an object has been persisted because it means we will no longer be able to retrieve it from the data store.
To ensure that the department's key cannot be changed for an existing department do the following:
In this way, the Text part is only enabled when creating a department. When an item is selected in the list, it means we are editing an existing persisted department; its object identifier therefore cannot be modified.
To get the List part to refresh, we can do the following:
The connection wire should be dotted indicating that we need to supply a parameter. The parameter we need to supply is the allInstances attribute of the TstDepartmentHome1 part. Connect value to allInstances.
Whenever the transaction is committed, the items of the List part are therefore refreshed with the allInstances of the TstDepartment class.