maks
maks

Reputation: 6006

ProvidesKey<T> in GWT

In GWT documentation in this article in "Keys" section said that ProvidesKey<T> allow us to identify the DTO object in cell list or cell table. Also there is a code sample that demonstrate that(they modify the contact and says that selection remains on that contact because they have provided a keyProvider).

Contact sarah = CONTACTS.get(3);
    selectionModel.setSelected(sarah, true);

    // Modify the name of the contact.
    sarah.name = "Sara";

But it also works without keyprovider. So the question is for what purposes we use ProvidesKey interface and why? At that example we can do the same without it.

Upvotes: 1

Views: 1224

Answers (1)

Thomas Broyer
Thomas Broyer

Reputation: 64541

The default implementation without a key provider uses equals().

Key providers become essential when you replace one object with another instance representing the same "entity", and with different content (so equals() wouldn't work); such as when retrieving an updated version from the server.

Upvotes: 3

Related Questions