how (multiple=true) presenter and view can be initialized with parameters using eventBus.addHandler?

747 Views Asked by At

With the Mvp4g architecture, (Only)one instance of the view (injected using @Presenter annotation)is associated with its presenter. In my case, I have a EntityView with its Presenter EntityPresenter. whenever user clicks on an Leaf node of a Navigator tree, I add a new Tab into TabSet. And this new Tab will contain an EntityView. So, I will have as many EntityView as many Tab in the TabSeT.

I have set multiple=true for EntityPresenter. EntityView's constructor accepts one argument.

@Inject
public EntityView(final Record view) {
  //some initialization
}

Question is, where I do (from another presenter):

EntityPresenter presenter = eventBus.addHandler(EntityPresenter.class);

I have one argument Record params which I want to pass to EntityView's constructor, how to do that? and annotating constructor(accepting argument) with @Inject will inject EntityView to EntityPresenter ?

1

There are 1 best solutions below

0
On

I suggest to use an EventHandler - that's a presenter without a view in mvp4g - which get an event showEntity(long key). In the onShowEntity(...) - method you can create the presenter with the statement:

EntityPresenter presenter = eventBus.addHandler(EntityPresenter.class);

With that reference of the instance, you can esaly set the key in the presenter. But keep in mind, you have to manage your presenter instances by yourself, when using multiple=true.