Search code examples
gwtuibinder

Create a reusable layout style uibinder


I want to create a layout uibinder to use inside other uibinders.

I have a layout pattern I use frequently it has a lot of html in it, and a place to put the content. I'd like to create a uibinder and put in it all the layout related html, then I'd use this uibinder (call it <my:myHTMLPanel>) inside my other uibinders and provide its inner html from within the xml file like so:

<my:myHTMLPanel>
    Hello world(+other wigets or html)
</my:myHTMLPanel>
<my:myHTMLPanel>
    How are you
</my:myHTMLPanel>?

is that even possible?


Solution

  • In your custom widget "myHTMLPanel", you can add this function:

    @UiChild
    public void addContent(Widget content) {
        // add the content in your custom widget
    }
    

    You can then use it like that in the ui.xml part:

    <my:myHTMLPanel>
        <my:content>
            <g:HTML> Hello world </g:HTML>
        </my:content>
    </my:myHTMLPanel>