手动实例化PresenterWidget(GWTP) [英] Instantiate a PresenterWidget (GWTP) manually
问题描述
我是GWT,GWTP的新手。
我有一个PresenterWidget,它可以多次实例化并添加到插槽中。我想以编程方式定义实例的数量。我只知道我通过注入它来创建一个新的Widget实例。
@Inject MyWidgetPresenter first;
@Inject MyWidgetPresenter秒;
// ...
我可以用新的实例化它吗?如何实例化视图?
我试图使用复合,因为它似乎是最聪明的解决方案,因为它不包含太多的逻辑。但我不能添加一个复合到一个插槽。
预先致谢 您可以获取 ClientGinjector
引用并调用getYourPresenter()方法。如果声明为 @Singleton
,它将返回相同的实例,如果不是,将会创建一个新实例,与使用new相同,但将所有参数注入构造函数。
这与添加@Inject到一个字段相同。
新增:
如果您没有必要的演示者,你的 ClientGinjector
,你可以简单地在这个接口上写一个getter方法。例如:
$ b
public interface ClientGinjector扩展了Ginjector {
....
SideMenuPresenter getSideMenuPresenter();
....
}
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
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();
....
}
这篇关于手动实例化PresenterWidget(GWTP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!