Our current solution is to have our presenters pass a dumbed down version of
the model to our views. In the case of our ContactsView, the presenter takes a
list of DTOs (Data Transfer Objects) and constructs a list of Strings that it
then passes to the view.
public ContactsPresenter implements Presenter { ... public void onSuccess(ArrayList<ContactDetails> result) { contactDetails = result; sortContactDetails(); List<String> data = new ArrayList<String>(); for (int i = 0; i < result.size(); ++i) { data.add(contactDetails.get(i).getDisplayName()); } display.setData(data); } ...}
The "data" object that is passed to the view is a very (and I mean very)
simplistic ViewModel — basically a representation of a more complex data model
using primitives. This is fine for a simplistic view, but as soon as you start to
do something more complex, you quickly realize that something has to give.
Either the presenter needs to know more about the view (making it hard to swap
out views for other platforms), or the view needs to know more about the data
model (ultimately making your view smarter, thus requiring more GwtTestCases).
The solution is to use generics along with a third party that abstracts any
knowledge of a cell's data type, as well as how that data type is rendered.