Example

For example:

@DomainObject(
    auditing=Auditing.ENABLED,
    autoCompleteRepository=CustomerRepository.class
    editing=Editing.ENABLED,
    updatedLifecycleEvent=Customer.UpdatedEvent.class

)
public class Customer {
    ...
}

View Models

The @DomainObject(nature=VIEW_MODEL) annotation, applied to a class, indicates that the class is a view model.

View models are not persisted to the database, instead their state is encoded within their identity (ultimately represented in the URL).

For example:

@DomainObject(nature=VIEW_MODEL)
public class CustomerViewModel {
    public CustomerViewModel() {}
    public CustomerViewModel(String firstName, int lastName) {
        this.firstName = firstName;
        this.lastName = lastName;
    }
    ...
}

Although there are several ways to instantiate a view model, we recommend that they are instantiated using an N-arg constructor that initializes all relevant state. The ServiceRegistry can then be used to inject dependencies into the view model. For example:

Customer cust = ...
CustomerViewModel vm = factoryService.viewModel(
    new CustomerViewModel(cust.getFirstName(), cust.getLastName()));

The view model’s memento will be derived from the value of the view model object’s properties. Any properties annotated with @Programmatic will be excluded from the memento. Properties that are merely hidden are included in the memento.

View models when defined using @DomainObject(nature=VIEW_MODEL) have some limitations:

  • view models cannot hold collections other view models (simple properties are supported, though)

  • collections (of either view models or entities) are ignored.

  • not every data type is supported,

However, these limitations do not apply to JAXB view models. If you are using view models heavily, you may wish to restrict yourself to just the JAXB flavour.