On Friday, July 22, 2011 1:03:55 PM UTC+2, Alexander Orlov wrote:
>
> class SuperClass {
> // ..
> static class Layout {
> // ...
> // put you @UiField, @UiHandler, etc. here
> @UiField
> Button test;
> }
>
> final Layout layout;
>
> public SuperClass() {
> this.layout = new Layout(this);
>
> RootPanel.get("widget").add(BINDER.createAndBindUi(this.layout));
>
D'oh, this is not at all the place to do this kind of thing. You should
stick with the "create something, then put it somewhere" pattern (rather
than a "create something, and it'll automatically show at a predefined
location")
> And where can I assign a handler to the "test" button?
>
In the Layout inner class, and you can simply defer to your outer class:
abstract class SuperClass {
...
static class Layout {
private final SuperClass owner;
...
// put you @UiField, @UiHandler, etc. here
@UiField
Button test;
@UiHandler("test")
void onTestClicked(ClickEvent event) {
this.owner.onTestClicked();
}
protected abstract void onTestClicked();
...
}
BTW, I'm not saying this is the best way of doing it, but it works, and it
shows what should be obvious: you're not forced to pass 'this' to
createAndBindUi (and incidentally to call createAndBindUi from an "UiBinder
owner class" instance).
I still believe it's better to make a reusable widget, using @UiChild to
allow adding children to it and events/delegate to communicate changes to
the container (or actually anything using it).
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-web-toolkit/-/g2T_OxUrHo8J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.