DTO Lifecycle
In contrast to the DTO classes that get generated for modeled displays, the DTO classes that get generated for a modeled layout (e.g. a web page) don’t have any properties that are related to components. Instead, they have three properties per display that is contained in the UI tree of the modeled layout.
The following table explains the differen types of properties. It presumes that there is the following model:
display Data {
...
}
layout MyPage {
link Children = Data;
}
Property in the class ‘MyPageDto’ | Purpose |
---|---|
DataDto data |
This object is being used for the data binding with JSF component in an XHTML file. |
DataDto dataDtoNew |
When an application has a ‘New’-button and follows a UI pattern that lets you persist a new entry only when all data has been entered for it, this property holds the corresponding DTO object. In this case, data and dataDtoNew reference the same object. |
List<DataDto> dataDtos |
This collection holds DTO objects that are going to be displayed on a section of a user interface. Each object that is referenced by data and dataDtoNew has to be included in the collection dataDtos . |
Moreover, some methods (apart from simple getters and setters) are added to the DTO class to ease and standardize the handling of DTO objects.
Method in the class ‘MyPageDto’ | Purpose |
---|---|
addNewDtoToData(DataDto dto) |
sets the DTO object for data , dataDtoNew and inserts it at the beginning of the collection dataDtos |
removeDtoFromData(DataDto dto) |
removes the DTO object from dataDtos and sets data and dataDtoNew to null if it previously referenced the passed dto |
addDataDtos(DataDto dto) |
adds the passed dto to the collection dataDtos |
selectFirstDtoOfData(DataDto dto) |
when dataDtos has at least one entry, the data field is set to the first entry of dataDtos |
Other generators that write code that uses DTO classes can depend on the existence of the properties and methods in the DTO classes. Apart from that, it is the responsibility of the developer who manually writes Java code to correctly use the DTO classes and its properties and methods.