开发者

GWT with MVP : add the same presenter to one container several times

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 开发者_C百科to ? I can provide you with additional information if needed.

Best regards,

Nils


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


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);


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜