Search code examples
gwtwidgetcompositegxt

Dynamically updating content of GWT Composite widgets


I created a widget that is a subclass of Composite and has a com.extjs.gxt.ui.client.widget.Viewport in it. Into this viewport I added my header component, a LayoutComponent (initially empty) and my footer component. I initialized the composite widget by calling initWidget at the end of the constructor that sets everything up ... something like this (some code removed for readability):

public class MyComposite extends Composite {
    ... 

    public MyComposite(...) {
        viewport = new Viewport();
        viewport.add(new Header());

        content = new LayoutContainer();
        viewport.add(content);

        viewport.add(new Footer());

        initWidget(viewport);
    }

    public void show(Widget... widgets) {
        content.removeAll();
        for (Widget widget: widgets) content.add(widget);
    }
}

Then I add an instance of this to the RootPanel:

MyComposite myComposite = new MyComposite(...);
RootPanel.get("myComposite").add(myComposite);

And guess what... that works! I see it. The header shows, the footer shows, and the content is blank at this point. Good. Then I make the call to show and add stuff to it. Not exactly as follows but for example:

myComposite.show(new Label(...));

But nothing happens. The code does run, the add(...) method gets called from the show(...) method, there are no exceptions, but nothing (new) shows up. I don't use a Label, but that is not the problem (verified, that works elsewhere). When I inspect the DOM in the browser, I see that there is a div for the content, like there was initially, but it remained empty (i.e. no body content).

What am I missing?

Thanks!


Solution

  • First off, are you extending GWT Composite or GXT Composite? If it is the GXT type you will need to call initComponent() on the viewport (rather than initWidget) as described here: http://dev.sencha.com/deploy/gxtdocs/com/extjs/gxt/ui/client/widget/Composite.html

    Also, try adding the following line to the end of your show method: content.layout(true);

    This will force GXT to layour the contents of your LayoutContainer, and you should at least see the new elements added to the DOM. If they still don't appear on the screen you need to change your Layout of your LayoutContainer.