Search code examples
gwtwidgetcompositeuibinder

Handling composite widget's events


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?


Solution

  • No. That would break the component design pattern.

    What you'd have to do is expose events on your LoginForm component that the MainViewImpl 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 to LoginForm 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.