UiBinder and abstract nested views

63 views
Skip to first unread message

Alex Dobjanschi

unread,
Aug 10, 2011, 7:52:56 AM8/10/11
to google-we...@googlegroups.com
Hello guys,
I was going through the UiBinder docs (http://code.google.com/webtoolkit/doc/latest/DevGuideUiBinder.html#Using_a_widget), and I was wondering if you could have a nested view, like this:

interface Header extends IsWidget {
 // have some methods here, not important
}

class AHeader implements Header {
 // implementation
}


Now, this header is part of a more complex view (provided UiBinder xml code below):
...
<g:HTMLPanel>
  <my:Header ui:field='header' />
  .... other widgets
</g:HTMLPanel>


And the class:
ApplicationView extends Composite {
 @UiField(provided=true) Header header;
 public ApplicationView (Header header) {
   this.header = header;
   // initWidget using UiBinder
 }
}

This looks ok to me -- however, this code will not actually work, and this is why (extract from generated UiBinder):
com.sample.Header header = owner.header;
....
f_HTMLPanel1.addAndReplaceElement(header, domId0Element);


It's quite obvious and straightforward -- the HTMLPanel#addAndReplaceElement method expects a Widget. However, the header is not an actual Widget, instead it could be retrieved as a Widget through IsWidget interface. Of course, I can switch the reference in .ui.xml, changing it from Header to AHeader (concrete implementation). However, this beats the purpose of having interface definitions for Views (which is not totally wrong to have, unless you want to give up unit testing -- and I don't).

Is there a way to fix this?
Thanks,
Alex.

Jens

unread,
Aug 10, 2011, 8:34:37 AM8/10/11
to google-we...@googlegroups.com
Maybe this will solve the issue:


I don't know in which GWT release it will be integrated.

But you can take the patch file and create your own HTMLPanel with the applied patch. Then you can use GWT's super-source feature to overload GWT's HTMLPanel with your patched one.


-- J.

Alex Dobjanschi

unread,
Aug 10, 2011, 8:56:51 AM8/10/11
to google-we...@googlegroups.com
That looks right. Thanks, Jens.

Is there any release version that will include this patch (anyone)?
Except that, looks like I'll compile the source code from svn.
Reply all
Reply to author
Forward
0 new messages