Hi guys,
I've been trying to find the best answer to the question above for a while now. Here is the problem:
* assume you have a view with textbox and a vertical panel. The textbox is used for searching, the vertical panel to display the found results.
In order to decouple everything, we'll define 2 interfaces:
interface ISearchView {
void populateResults (List<String> results);
setPresenter (ISearchPresenter p);
}
interface ISearchPresenter {
void doSearch (String query);
}
* using the code above, I can safely bind events in view, that dispatch business execution to a presenter (set via #setPresenter). Everything is very clean & organized.
However, when I'm implementing an Activity, here is how it would look like:
class SearchActivity extends AbstractActivity implements ISearchPresenter {
@Override
public void start(final AcceptsOneWidget panel, EventBus eventBus) {
ISearchView view = clientFactory.getSearchView();
view.setPresenter (this);
panel.setWidget (view);
}
@Override
public void onSearch (String query) {
// Execute some sync/async call.
clientFactory.searchService().search (query, .......);
// HOW DO I SEND RESULTS BACK TO VIEW??
}
}
I don't know how to access the view instance, in order to populate it with some results. One way, which I honestly think it's uberly wrong -- is to access it through clientFactory.getSearchView. But this basically forces me to have a singleton scope of that view. Not acceptable, imo.
Thanks.