tags:

views:

349

answers:

3

Hello,

I'm working with GWT with the MVP pattern, actually implementing a search results page. The search results are represented by a picture + some info. I created a presenter and a view for a search result (I'll call this little square "thumbnail" for now on), so that I can add it several times to the search results page, and use it in other pages later on if necessary.

In my SearchResultsPresenter, which disposes of a thumbnailPresenter, I'm simply looping on my search results, giving the right info to the thumbnailPresenter, and adding the "asWidget" of the view to a container:

display.getResultsContainer().add(goodPresenter.getDisplay().asWidget());

The problem is that I only see one search result : it looks like adding the same presenter several times to a container is not supposed to be done like this. I've been browsing the Internet for a while now, but can't find any relevant solution to my problem :(

Has anyone got a solution or a direction to point me to ? I can provide you with additional information if needed.

Best regards,

Nils

+1  A: 

You must make sure your presenter creates for every call a new Widget. Otherwise you are adding the same widget over and over again.

Drejc
Yep, this doesn't look like a GWT problem per se, you are probably trying to add the same `Widget` (display) over and over again to a `Panel` (which will, of course, result in it showing only once) - for debugging purposes you can for example `assert` that the `Panel` doesn't have that `Widget` using `getWidgetIndex` or something similar from the container of your choice.
Igor Klimer
A: 

Yeah indeed, one solution is to create a new View and a new Presenter. This might seem weird, but I thought that this was best-practise forbidden. And this was a wrong thought !

So just by creating a new one everytime and adding it, it works perfectly.

Nils
+1  A: 

Are you using Google Gin combined with gwt-presenter framework?

The GWT-Presenter's AbstractPresenterModule has method bindPresenter which binds the specified presenter class as a singleton.

Let's say you loop through your result data records and add a new presenter which you get from a Provider. If this presenter is bound as a singleton, the returned widget will always be the same, hence you see only one result in your page.

To sum it up, instead of doing this:

bindPresenter(FooPresenter.class, FooPresenter.Display.class, FooDisplay.class);

do this:

bind(FooPresenter.class);
bindDisplay(FooPresenter.Display.class, FooDisplay.class);
martinsb