gwtgwtpgwt-platform

Instantiate a PresenterWidget (GWTP) manually


i am new to GWT, GWTP.

I have a PresenterWidget which gets instantiated multiple times and gets added to a slot. I want to define the amount of instances programmatically. I only know that I make a new Instance of the Widget by Injecting it.

@Inject MyWidgetPresenter first; 
@Inject MyWidgetPresenter second; 
// ...

Can I instantiate it with new? how do instantiate the view?

I tried to use a composite because it seemed to be the smartest solution, because it doesnt contain much logic anyway. But I cant add a composite to a slot.

Thanks in advance


Solution

  • You can get the ClientGinjector reference and call a getYourPresenter() method. If it's declared as @Singleton it will return the same instance, if is not will create a new instance, same as using new, but injecting all parameters to the constructor. It will be the same as adding @Inject to a field.

    Added: If you don't have the required presenter there, at your ClientGinjector, you can simply write a getter method at that interface. Ex:

    public interface ClientGinjector extends Ginjector {
        ....
        SideMenuPresenter getSideMenuPresenter();
        ....
    }