tags:

views:

1525

answers:

3

When working with MVP in GWT how would you work with a table? For example if you had a table of users does your view look like this?

public interface MyDisplay{

HasValue<User> users();

}

or would it be more like this?

public interface MyDisplay{

HasValue<TableRow> rows();

}

MVP makes a ton of sense until you start dealing with widgets that need to display lists of non-primitive data. Can anybody shed some light?

This mailing list archive appears to ask the same question but never reaches a solid resolution...

http://www.mail-archive.com/[email protected]/msg24546.html

+3  A: 

HasValue<User> or HasValue<TableRow> would not work in this case, because this would only permit handling a single row. You could maybe use a HasValue<List<User>> but that would mean, that your view has to render the entire table on each change.

I might be wrong, but I think for tables its best to use a Supervising Presenter instead of the Passive View. Have a look at the PagingScrollTable widget in the GWT Incubator:

public class PagingScrollTable<RowType> extends AbstractScrollTable implements
    HasTableDefinition<RowType>, ... {
  ...
  TableModel<RowType> getTableModel() 
  ...
}

For a PagingScrollTable, a MutableTableModel<RowType> is used as implementation of TableModel<RowType>.

MutableTableModel<RowType> in turn implements the following interfaces:

HasRowCountChangeHandlers, HasRowInsertionHandlers, HasRowRemovalHandlers, HasRowValueChangeHandlers<RowType>

The PagingScrollTable registers itself as listener on the MutableTableModel and therefore gets very fine-grained notifications of updates. The resulting implementation should be very performant.

Nightscape
It is possible to have a table using a passive view but you essentially need to redraw the entire table every time you want to add/remove a row or sort anything. This is because the display interface would have a method such as setRows(List<List<Widget>>widgets) where the entire table gets set and the view simply lays out many many widgets in a grid (one List<Widget> per row where each Widget is a column).In terms of performance I am not sure how slow it would really be as I have not tested with large amounts of data yet. I assume using a table model would be faster (if speed is an issue).
Benju
+1  A: 

this discussion does reach a resolution for similar question:

http://groups.google.com/group/google-web-toolkit/browse_thread/thread/4887a7565d05f349?tvc=2

grigory
A: 

This might be a very interesting blog post:

http://www.draconianoverlord.com/2010/03/31/gwt-mvp-tables.html

u2ix