HintIdProvider

Provides a SPI for view models to implement to represent their "logical" identity (stable even if the view model’s state changes).

Hints are stored against the Bookmark of a domain object, essentially the identifier of the domain object. For a domain entity this identifier is fixed and unchanging but for view models the identifier changes each time the view model’s state changes (the identifier is basically a digest of the object’s state). This means that any hints stored against the view model’s bookmark are in effect lost as soon as the view model is modified.

This SPI therefore allows a view model to take advantage of the hinting mechanism of the viewer by providing a "logical" identity stored which hints for the view model can be stored.

API

HintIdProvider.java
interface HintIdProvider {
  String hintId()
}

Implementation

The framework provides no implementations of this SPI.

Usage Example

For example, suppose that there’s a view model that wraps a Customer and its Orders. For this view model the Customer represents the logical identity. This view model might therefore be implemented as follows:

@XmlRootElement("customerAndOrders")
@XmlAccessType(FIELD)
public class CustomerAndOrders implements HintStore.HintIdProvider {

    @Getter @Setter
    private Customer customer;

    // ...

    @Programmatic
    public String hintId() {
        bookmarkService.bookmarkFor(getCustomer()).toString();
    }

    @XmlTransient
    @Inject BookmarkService bookmarkService;
}