tags:

views:

617

answers:

4

Right now I'm playing with ScrollTable from GWT Incubator. I'm trying to make functionality when user select one row then click on Edit button and then he will be able to edit that particular Object. Right now I have to check what row has been selected

Integer secRowPosition = e.getSelectedRows().iterator().next().getRowIndex();

then query my dataTable for row and column to select unique id and then query my database for that object:

myObject = getObjectFromDBbyID(dataTable.getText(secRowPosition, 0));

This method works fine for me, but is it possible to get that object straight from the table and not form database so I can save some time without querying my database.

I assume I need to assign each object to the row in ScrollTable in order to do that. Any ideas?

A: 

If you're populating your table with a list of objects, simply get the index of the table row and get the corresponding object from the list.

KevMo
What if user sort the table, then the indexed id's will be different than ones that are in the ArrayList.
Maksim
+1  A: 

There may be better ways but one approach I have used is to store a reference to the object you wish to edit inside a Button widget. You'd do this by extending Button and adding an instance to every row.

The appropriate object is then readily available whenever the corresponding edit button is clicked.

AlexJReid
A: 

Extending Label to have an id field would let you sort on it as well.

A: 

If you have some sort of unique id displayed in the table, you can keep a HashMap<YourId,YourObject>.

This will not be impacted by sorting.

Nicolas