GWT UiBinder: How to make a custom AbsolutePanel which uses the "at" element?
Asked Answered
S

1

4

Trying to extend AbsolutePanel, my UiBinder won't allow the <g:at> element which is normally ok for straight AbsolutePanels. How do I make my AbsolutePanel subclass able to use the <g:at> element? And more generally, can I make custom UiBinder keywords for my own custom Widgets like "at", "west", "layer" etc.?

Seasickness answered 2/8, 2012 at 16:50 Comment(0)
S
8

You can use @UiChild to declare special functions in your widgets accessible in UiBinders.

for example,

class MyPanel extends AbsolutePanel {

    @UiChild
    public void addAt(Widget w, String parameter1, String parameter2) {
         ....

Then, in your uiBinder, you can say

<custom:MyPanel>
    <custom:at parameter1="HI" parameter2="Anything you like!">
        <g:AnySingleWidget />
    </custom:at>
</custom:MyPanel>

See @UiChild at http://google-web-toolkit.googlecode.com/svn/javadoc/latest/com/google/gwt/uibinder/client/UiChild.html

Slavin answered 2/8, 2012 at 21:15 Comment(4)
I wish GWT docs documented the parameter feature you've demonstrated here. It was exactly what I was looking for, but impossible to uncover through official documentation.Leidaleiden
It's also worth pointing out that any parameters after "Widget w" that you specify using primitive types, will show up as editable properties in the UiBinder designer, on the child widget, grouped under the heading UiChild. So in the example above, <g:AnySingleWidget /> will have properties parameter1 and parameter2 in the properties pane under the heading "UiChild".Leidaleiden
And if you're using an @UiChild( tagname = "something" ) annotation, the tagname must be lowercase, or be an actual class name from the same package as the class with your UiChild add method, or the Designer will throw errors. These errors don't interfere with Dev mode or compilation, but they are annoying.Leidaleiden
Hi, do I always have to pass a widget or can I just pass 2 parameters?Christophe

© 2022 - 2024 — McMap. All rights reserved.