GWT& GIN:如何使用 UIBinder 将 PlaceController 注入到小部件中
我有一个在 UIBinder 中使用的 InlineLabel 子类。如何通过 GIN 将 PlaceController 注入其中,以便该小部件可以在 UIBinder 中使用? (回想一下,UIBinder 需要一个无参数构造函数。)
如果这是不可能的,那么使 PlaceController 可用于小部件以便小部件可以在 onClick() 事件期间使用它的最简洁方法是什么?
编辑:
在这种情况下,我不确定 MVP 是否真的是最佳解决方案(不过,我很高兴您改变主意。)
我将在 UIBinder 中声明数十个这样的 InlineLabel 实例foo.ui.xml 文件。如果我实现 MVP,这意味着将每个实例声明为视图中的 @UiField 成员。当我有这么多的时候,这变得相当笨拙。这就是为什么我希望以半自动的方式将 PlaceController 注入每个 InlineLabels 中,并避免必须手动将它们连接到视图中。
如果有一种方法可以将演示者注入到每个 InlineLabels 中,那么委托可以执行如下操作:
public class MyInlineLabelSubclass {
// ...
public void onClick(ClickEvent event)
{
presenter.labelClicked(this);
}
}
I have an InlineLabel subclass that I used in UIBinder. How can I inject a PlaceController into it via GIN, so that the widget can be used in UIBinder? (recall that UIBinder requires a no-args constructor.)
If that's not possible, what's the cleanest way to make a PlaceController available to a widget so that it can be used by the widget during onClick() events?
Edit:
I'm not sure MVP is really the best solution in this case (I'm happy to have you change my mind, however.)
I will have dozens of these InlineLabel instances declared in my UIBinder foo.ui.xml file. If I implement MVP, that means declaring each of these instances as @UiField members in the view. That gets rather unwieldy when I have so many of them. That's why I was hoping to inject the PlaceController into each of the InlineLabels in a semi-automated way, and avoid having to manually wire them into the view.
It would also be acceptable if there were a way to inject the presenter into each of the InlineLabels... then the delegation could be done something like:
public class MyInlineLabelSubclass {
// ...
public void onClick(ClickEvent event)
{
presenter.labelClicked(this);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
@UiHandler
注释将处理程序添加到 UiBinder 元素,而无需使用@UiField
引用:并且在视图中:
不要为您的小部件提供直接句柄到 PlaceController - 委托给视图的 Presenter(通过回调或 Presenter 接口)。请参阅 http://code.google.com/webtoolkit/doc/latest/ DevGuideMvpActivitiesAndPlaces.html#Views
You can use the
@UiHandler
annotation to add a handler to a UiBinder element without having a@UiField
reference:And in the view:
Don't give your widget a direct handle to a PlaceController - delegate to the view's Presenter (via. a callback or a Presenter interface). See http://code.google.com/webtoolkit/doc/latest/DevGuideMvpActivitiesAndPlaces.html#Views
我在网上看到过一个示例,其中超链接是直接从 PlaceController 使用的名称标记构建的。例如。
有关此示例的更多信息,请参阅此处:
http://code.google .com/p/gwt-platform/wiki/SimpleNestedSample#Step_3:_Creating_a_custom_widget
I've seen an example online where hyperlinks were built directly from the name tokens used by the PlaceController. eg.
See here for more on this example:
http://code.google.com/p/gwt-platform/wiki/SimpleNestedSample#Step_3:_Creating_a_custom_widget