我正在使用 UiBinder 创建一个复合小部件。该小部件是一个登录表单,因此基本上它有标签、文本框和按钮。我计划在也使用 UiBinder 声明的视图中使用此小部件。所以,基本上我已经有了这些文件:LoginForm.ui.xml、LoginForm.java、MainViewImpl.ui.xml 和 MainViewImpl.java。
我必须使用 @UiHandler 注释在 LoginForm.java 中定义登录表单的事件处理程序,但是我想知道是否有办法在 MainView.java 中定义这些事件处理程序。这可能吗?
I'm creating a composite widget using UiBinder. The widget is a login form, so basicly it has labels, textboxes and a button. I'm planning to use this widget within a view which is also declared using UiBinder. So, basicly I've got these files: LoginForm.ui.xml, LoginForm.java, MainViewImpl.ui.xml and MainViewImpl.java.
I'd have to define the event handlers of the login form in LoginForm.java using the @UiHandler annotation, however I'd like to know if there is a way to define those event handlers in MainView.java. Is that possible?
发布评论
评论(1)
不。那会破坏组件设计模式。
您所要做的就是在您的
LoginForm
组件上暴露事件,MainViewImpl
将能够侦听这些事件。如果这是“一次”,我就不会费心创建事件,而是简单地使用
MainViewImpl
实现并传递给LoginForm
的回调接口> 让它回调。这类似于 Presenter 接口“nofollow">MVP – 第二部分文章通知演示者。
No. That would break the component design pattern.
What you'd have to do is expose events on your
LoginForm
component that theMainViewImpl
will be able to listen.If it's a "one shot" though, I wouldn't bother creating events and instead simply use a callback interface that
MainViewImpl
implements and passes toLoginForm
for it to call it back.This is similar to the
Presenter
interface called back by the view in the MVP – Part II article to notify the presenter.