Thank you for reporting this bug. We will make it our priority to review this report.
[CLOSED] Unable to add more than one widget to a ContentPanel?
Feature or bug?
Here's a very simple example code:
The problem is, only the last widget (btn2) is really rendered. getWidgetCount() returns 1, as if btn1 was never added.
ContentPanel view = new ContentPanel();
TextButton btn1 = new TextButton("1");
TextButton btn2 = new TextButton("2");
System.out.println("view.getWidgetCount() = " + view.getWidgetCount()); // = 1
If it's a feature (like "you have to add another panel wrapping all buttons") - what would be getWidgetCount() for?
ContentPanel is a SimpleContainer and so only contains one child at a time. You need to wrap them in a VerticalLayoutContainer for example
Thank you, I didn't notice the new SimpleContainer concept. I guess, it should be fixed/improved though, since the SimpleContainer.add() method says:
And that's what ContentPanel (and other SimpleContainer subclasses) don't do. And therefore it's not very intuitive, especially if you want to migrate your 2.x application, where you could use ContentPanel.add() to add more than one widget.
The expectation is that this method would be overridden by a child object.
Also, as mentioned, inherited methods like "getWidgetCount()" or "getWidget(int)" lead to even more confusion. Seeing this method on a SimpleContainer make a developer assume, it could actually contain more than one widget. Making those methods private, for example, would prevent such assumptions.
Theses methods are comming from a GWT interface.
In GXT 3 the layouts are bound into the containers. We are still working on adding more javadocs, however there are currently no plans to change the design. Contentpanel does not have any insert method. SimplePanel from GWT behaves also exactly the same way, only that it will throw an exception.
If you take a look at Widget.removeFromParent you will see that the HasWidget interface (that has the add method) is required).
If you require to handle more than one widget, you need to add another container into the ContentPanel, like a FlowLayoutContainer.
In GXT 2 the add method maybe always works. However when using a FitLayout only the first child would have been used, same in a CenterLayout. In GXT 3, the container takes care of all this.