Projections
A common use case for view models is to act as a projection of some underlying entity, to decorate that entity with additional behaviour (or remove existing behaviour) for some particular business context.
Very often the object that is of interest to the end-user is the underlying entity, not the view model per se. If the view model is displayed within a table (on a home page, say), then when the user clicks the entity/icon link for the view model, they will in fact want to drill-down to the underlying entity and skip the view model completely.
The projecting() element allows the view model to indicate which of its properties holds a reference to the underlying entity of which it is a projection.
For example:
@DomainObject(nature=VIEW_MODEL)
public InvoiceSummary {
@Property(
projecting = Projecting.PROJECTED, (1)
hidden = Where.EVERYWHERE (2)
)
@Getter @Setter
private Invoice invoice;
public LocalDate getDueDate() { (3)
return invoice.getDueDate();
}
...
}
| 1 | indicates that this property holds a reference to the underlying entity |
| 2 | the underlying entity is typically (though not necessarily) hidden |
| 3 | typical implementation of the properties of the underlying entity that are being projected in the view model. |