Search code examples
javapostgresqlgwtgwt2postgresql-9.1

Key provider with Postgres and GWT


For my GWT project,

I initially constructed a List and a *KEY_PROVIDER* to uniquely identify my records in the List. Now instead of List I have connected to the Postgres database and am wondering as to if I need to pass an object of the ProvidesKey to the database OR remove it completely when using a database.

EARLIER-

// Make a provider, connect the List with the provider!
final ListDataProvider<Contact> sortProvider = new ListDataProvider<Contact>(KEY_PROVIDER);
sortProvider.setList(CONTACTS);

NOW-

// Create a data provider.
MyDataProvider sortProvider = new MyDataProvider();
sortProvider.addDataDisplay(table);

I am not sure how it needs to be done now?

Do I need to pass-

MyDataProvider sortProvider = new MyDataProvider(KEY_PROVIDER);

instead?

What should be the best practice? Thanks!


Solution

  • Well the ProvidesKey interface is only used on the client side (GWT) to identify your objects. This is important for knowing which object in a list is selected and also for manually selecting another row in your CellTable/CellList.

    If you don't specify a ProvidesKey implementation the CellWidgets will use the equals function of your DTO's to check if they are equal or not. You might run into problems if the object itself changes. So it's always good practice to specify a ProvidesKey implementation and doesn't depend on whether you use a ListDataProvider, a AsyncDataProvider or a custom data provider.

    BTW what is MyDataProviderin your example? Is it a subclass of AsyncDataProvider?